Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from tabulate import tabulate
|
| 3 |
+
from eventbrite_scrapper import Eventbrite
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
# Initialize Eventbrite API Client
|
| 9 |
+
client = Eventbrite()
|
| 10 |
+
|
| 11 |
+
# Fetch events
|
| 12 |
+
def fetch_events():
|
| 13 |
+
return client.search_events.get_results(
|
| 14 |
+
region="ca--los-angeles", # Can change region
|
| 15 |
+
dt_start="2024-11-28",
|
| 16 |
+
dt_end="2024-12-25",
|
| 17 |
+
max_pages=4,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Define Event RAG Pipeline
|
| 21 |
+
class EventbriteRAGPipeline:
|
| 22 |
+
def __init__(self, events, embedding_model='all-MiniLM-L6-v2'):
|
| 23 |
+
self.events = events
|
| 24 |
+
self.model = SentenceTransformer(embedding_model)
|
| 25 |
+
self.event_embeddings = self._compute_embeddings()
|
| 26 |
+
|
| 27 |
+
def _compute_embeddings(self):
|
| 28 |
+
def event_to_text(event):
|
| 29 |
+
return " ".join(filter(None, [event.name, event.short_description]))
|
| 30 |
+
return self.model.encode([event_to_text(event) for event in self.events])
|
| 31 |
+
|
| 32 |
+
def query_events(self, query, top_k=5):
|
| 33 |
+
query_embedding = self.model.encode(query).reshape(1, -1)
|
| 34 |
+
similarities = cosine_similarity(query_embedding, self.event_embeddings)[0]
|
| 35 |
+
top_indices = similarities.argsort()[-top_k:][::-1]
|
| 36 |
+
return [self.events[idx] for idx in top_indices]
|
| 37 |
+
|
| 38 |
+
class EventEvaluator:
|
| 39 |
+
def __init__(self, pipeline):
|
| 40 |
+
self.pipeline = pipeline
|
| 41 |
+
|
| 42 |
+
def evaluate_query(self, query):
|
| 43 |
+
"""Evaluate a single query and return results."""
|
| 44 |
+
top_events = self.pipeline.query_events(query)
|
| 45 |
+
results = []
|
| 46 |
+
for event in top_events:
|
| 47 |
+
result = {
|
| 48 |
+
"Event Name": event.name,
|
| 49 |
+
"Online Event": event.is_online_event,
|
| 50 |
+
"Start Time": event.start_datetime,
|
| 51 |
+
"Venue Address": event.primary_venue.address.address_1,
|
| 52 |
+
"Venue Name": event.primary_venue.name,
|
| 53 |
+
"Tickets URL": event.tickets_url,
|
| 54 |
+
"Language": event.language,
|
| 55 |
+
"Description": event.short_description,
|
| 56 |
+
"Categories": [tag.text for tag in event.tags_categories],
|
| 57 |
+
}
|
| 58 |
+
results.append(result)
|
| 59 |
+
return results
|
| 60 |
+
|
| 61 |
+
# Streamlit UI
|
| 62 |
+
st.title("Eventbrite Event Search")
|
| 63 |
+
query = st.text_input("Enter event type (e.g., concerts, hackathons, conferences)")
|
| 64 |
+
if st.button("Search"):
|
| 65 |
+
sample_events = fetch_events()
|
| 66 |
+
rag_pipeline = EventbriteRAGPipeline(sample_events)
|
| 67 |
+
evaluator = EventEvaluator(rag_pipeline)
|
| 68 |
+
results = evaluator.evaluate_query(query)
|
| 69 |
+
|
| 70 |
+
if results:
|
| 71 |
+
table = [
|
| 72 |
+
[
|
| 73 |
+
result["Event Name"],
|
| 74 |
+
result["Online Event"],
|
| 75 |
+
result["Start Time"],
|
| 76 |
+
result["Venue Address"],
|
| 77 |
+
result["Venue Name"],
|
| 78 |
+
result["Description"],
|
| 79 |
+
result["Tickets URL"],
|
| 80 |
+
result["Language"],
|
| 81 |
+
result["Categories"],
|
| 82 |
+
]
|
| 83 |
+
for result in results
|
| 84 |
+
]
|
| 85 |
+
st.text(tabulate(table, headers=["Event Name", "Online Event", "Start Time", "Venue Address", "Venue Name", "Description", "Tickets URL", "Language", "Categories"], tablefmt="grid"))
|
| 86 |
+
else:
|
| 87 |
+
st.write("No results found.")
|