Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.metrics.pairwise import cosine_similarity | |
# Sample Data (REPLACE WITH YOUR ACTUAL DATABASE) | |
data = { | |
'event_id': [101, 102, 103, 104, 105], | |
'title': ['Hiking Meetup', 'Book Club Discussion', 'Gardening Workshop', 'Coding Class', 'Yoga Session'], | |
'description': ['Explore local trails', 'Discuss "The Great Gatsby"', 'Learn basic gardening', 'Python programming basics', 'Relaxing yoga practice'], | |
'tags': ['hiking, nature, outdoors', 'books, literature, reading', 'gardening, plants, nature', 'coding, programming, python', 'yoga, fitness, relaxation'] | |
} | |
events_df = pd.DataFrame(data) | |
def recommend_activities(interests, num_recommendations=3): | |
if not interests: | |
return "Please enter your interests." | |
user_interests = interests.lower() | |
tfidf = TfidfVectorizer() | |
tfidf_matrix_events = tfidf.fit_transform(events_df['tags']) | |
tfidf_matrix_user = tfidf.transform([user_interests]) | |
similarities = cosine_similarity(tfidf_matrix_user, tfidf_matrix_events) | |
top_indices = similarities.argsort()[0][-num_recommendations:][::-1] | |
recommendations = events_df.iloc[top_indices][['title', 'description']].values.tolist() | |
return recommendations | |
def create_event(title, description, location, date_time, tags): | |
print(f"Event created: {title}, {description}, {location}, {date_time}, {tags}") | |
return "Event created successfully!" | |
with gr.Blocks() as demo: | |
gr.Markdown("# AI Community Builder") | |
with gr.Row(): | |
with gr.Column(): | |
interests_input = gr.Textbox(label="Your Interests (comma-separated)", lines=2, placeholder="e.g., hiking, reading, cooking") | |
num_recs_input = gr.Slider(label="Number of Recommendations", minimum=1, maximum=5, value=3, step=1) | |
recommend_button = gr.Button("Get Recommendations") | |
with gr.Column(): | |
recommendations_output = gr.Dataframe(headers=["Title", "Description"], datatype=["str", "str"], interactive=True) | |
recommend_button.click(fn=recommend_activities, inputs=[interests_input, num_recs_input], outputs=recommendations_output) | |
with gr.Accordion("Create a New Event", open=False): | |
with gr.Row(): | |
title_input = gr.Textbox(label="Event Title", placeholder="Enter event title") | |
description_input = gr.Textbox(label="Description", lines=3, placeholder="Enter a brief description") | |
with gr.Row(): | |
location_input = gr.Textbox(label="Location", placeholder="Enter location details") | |
datetime_input = gr.Textbox(label="Date & Time (YYYY-MM-DD HH:MM)", placeholder="Enter date and time") | |
tags_input = gr.Textbox(label="Tags (comma-separated)", placeholder="Enter relevant tags") | |
create_event_button = gr.Button("Create Event") | |
create_event_button.click(fn=create_event, inputs=[title_input, description_input, location_input, datetime_input, tags_input], outputs=gr.Textbox(label="Result")) | |
demo.launch() |