CoolFace
Apppublic

sharan1/DM_Project_Suggestions_V2

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py118 linesDownload Raw Back to root
1import gradio as gr2import pickle3import os4import re5 6# # Visitor counter7# def update_visitor_count():8#     count_file = "visits.txt"9#     try:10#         if os.path.exists(count_file):11#             with open(count_file, "r") as f:12#                 count = int(f.read().strip()) + 113#         else:14#             count = 115#         with open(count_file, "w") as f:16#             f.write(str(count))17#         return count18#     except:19#         return 0  # Fallback if file access fails20 21# # Increment count on app start22# visitor_count = update_visitor_count()23 24# Load the .pkl file25with open("recommender.pkl", "rb") as f:26    saved_data = pickle.load(f)27    vectorizer = saved_data["vectorizer"]28    model = saved_data["model"]29 30# Prediction function31def recommend_project(bio):32    if not bio.strip():33        return "Please enter a bio!"34    X_bio = vectorizer.transform([bio])35    prediction = model.predict(X_bio)[0]36    return f"Suggested Project: {prediction}"37 38# Feedback function39def save_feedback(bio, suggestion, feedback):40    if not feedback.strip():41        return "Please enter feedback!"42    with open("feedback.csv", "a", newline="") as f:43        writer = csv.writer(f)44        writer.writerow([bio, suggestion, feedback])45    return "Thanks for your feedback!"46 47suggested_bios = """48**Try these example bios (copy-paste one):**491. I want to predict diabetes with Python502. I like analyzing marketing data513. I’m curious about movie genres and coding \n52*. OR You can copy-paste your LinkedIn profile bio!53"""54 55# Create Gradio interface56interface = gr.Interface(57    fn=recommend_project,58    inputs=gr.Textbox(59        lines=5,60        placeholder="Enter your bio (e.g., I love coding and health data)..."61    ),62    outputs="text",63    title="DM Project Recommender",64    description="Type your interests to get a DM project suggestion! Try the example bios or write your own. \n\n" + suggested_bios + "\n\n**Follow me on GitHub for more DM/ML projects: [bsharan](https://github.com/bsharan)**"65)66 67# bio_input = gr.Textbox(lines=5, placeholder="Enter your bio here...")68# submit_button = gr.Button("Get Recommendation")69# output = gr.Textbox(label="Recommendation")70# feedback_input = gr.Textbox(lines=2, placeholder="Did the suggestion make sense? Tell us!")71# feedback_button = gr.Button("Submit Feedback")72# feedback_output = gr.Textbox(label="Feedback Status")73 74# submit_button.click(75#     fn=recommend_project,76#     inputs=bio_input,77#     outputs=[output, feedback_input]78# )79# feedback_button.click(80#     fn=save_feedback,81#     inputs=[bio_input, output, feedback_input],82#     outputs=feedback_output83# )84 85# Create Gradio Blocks interface86with gr.Blocks() as app:87    gr.Markdown("# Project Recommender")88    gr.Markdown(89        "Type your interests to get a project suggestion!\n\n" +90        suggested_bios +91        "\n\n**Follow me on GitHub for more ML projects: [bsharan](https://github.com/bsharan)**"92    )93    bio_input = gr.Textbox(lines=5, placeholder="Enter your bio here...")94    submit_button = gr.Button("Get Recommendation"95    output = gr.Textbox(label="Recommendation")96    # feedback_input = gr.Textbox(lines=2, placeholder="Did the suggestion make sense? Tell us!")97    # feedback_button = gr.Button("Submit Feedback")98    # feedback_output = gr.Textbox(label="Feedback Status")99    100#     submit_button.click(101#         fn=recommend_project,102#         inputs=bio_input,103#         outputs=[output, feedback_input]104#     )105#     feedback_button.click(106#         fn=save_feedback,107#         inputs=[bio_input, output, feedback_input],108#         outputs=feedback_output109#     )110 111 112 113# # Launch (Hugging Face handles this)114# if __name__ == "__main__":115#     interface.launch()116#     # interface.launch(share=True)117 118# # app.launch()