Spaces:
Runtime error
Runtime error
Upload app3.py
Browse files
app3.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 4 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 5 |
+
|
| 6 |
+
# Sample Data (REPLACE WITH YOUR ACTUAL DATABASE)
|
| 7 |
+
data = {
|
| 8 |
+
'event_id': [101, 102, 103, 104, 105],
|
| 9 |
+
'title': ['Hiking Meetup', 'Book Club Discussion', 'Gardening Workshop', 'Coding Class', 'Yoga Session'],
|
| 10 |
+
'description': ['Explore local trails', 'Discuss "The Great Gatsby"', 'Learn basic gardening', 'Python programming basics', 'Relaxing yoga practice'],
|
| 11 |
+
'tags': ['hiking, nature, outdoors', 'books, literature, reading', 'gardening, plants, nature', 'coding, programming, python', 'yoga, fitness, relaxation']
|
| 12 |
+
}
|
| 13 |
+
events_df = pd.DataFrame(data)
|
| 14 |
+
|
| 15 |
+
def recommend_activities(interests, num_recommendations=3):
|
| 16 |
+
if not interests:
|
| 17 |
+
return "Please enter your interests."
|
| 18 |
+
|
| 19 |
+
user_interests = interests.lower()
|
| 20 |
+
tfidf = TfidfVectorizer()
|
| 21 |
+
tfidf_matrix_events = tfidf.fit_transform(events_df['tags'])
|
| 22 |
+
tfidf_matrix_user = tfidf.transform([user_interests])
|
| 23 |
+
similarities = cosine_similarity(tfidf_matrix_user, tfidf_matrix_events)
|
| 24 |
+
top_indices = similarities.argsort()[0][-num_recommendations:][::-1]
|
| 25 |
+
recommendations = events_df.iloc[top_indices][['title', 'description']].values.tolist()
|
| 26 |
+
return recommendations
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def create_event(title, description, location, date_time, tags):
|
| 30 |
+
print(f"Event created: {title}, {description}, {location}, {date_time}, {tags}")
|
| 31 |
+
return "Event created successfully!"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown("# AI Community Builder")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
with gr.Column():
|
| 39 |
+
interests_input = gr.Textbox(label="Your Interests (comma-separated)", lines=2, placeholder="e.g., hiking, reading, cooking")
|
| 40 |
+
num_recs_input = gr.Slider(label="Number of Recommendations", minimum=1, maximum=5, value=3, step=1)
|
| 41 |
+
recommend_button = gr.Button("Get Recommendations")
|
| 42 |
+
|
| 43 |
+
with gr.Column():
|
| 44 |
+
recommendations_output = gr.Dataframe(headers=["Title", "Description"], datatype=["str", "str"], interactive=True)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
recommend_button.click(fn=recommend_activities, inputs=[interests_input, num_recs_input], outputs=recommendations_output)
|
| 48 |
+
|
| 49 |
+
with gr.Accordion("Create a New Event", open=False):
|
| 50 |
+
with gr.Row():
|
| 51 |
+
title_input = gr.Textbox(label="Event Title", placeholder="Enter event title")
|
| 52 |
+
description_input = gr.Textbox(label="Description", lines=3, placeholder="Enter a brief description")
|
| 53 |
+
with gr.Row():
|
| 54 |
+
location_input = gr.Textbox(label="Location", placeholder="Enter location details")
|
| 55 |
+
datetime_input = gr.Textbox(label="Date & Time (YYYY-MM-DD HH:MM)", placeholder="Enter date and time")
|
| 56 |
+
tags_input = gr.Textbox(label="Tags (comma-separated)", placeholder="Enter relevant tags")
|
| 57 |
+
create_event_button = gr.Button("Create Event")
|
| 58 |
+
|
| 59 |
+
create_event_button.click(fn=create_event, inputs=[title_input, description_input, location_input, datetime_input, tags_input], outputs=gr.Textbox(label="Result"))
|
| 60 |
+
|
| 61 |
+
demo.launch()
|