Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Function to extract Strava activity details
|
| 7 |
+
def extract_activity_data(url):
|
| 8 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
| 9 |
+
response = requests.get(url, headers=headers)
|
| 10 |
+
|
| 11 |
+
if response.status_code != 200:
|
| 12 |
+
return "Failed to fetch activity details."
|
| 13 |
+
|
| 14 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 15 |
+
|
| 16 |
+
# Extract Title and Some Metrics (Modify as needed)
|
| 17 |
+
title = soup.find('title').text if soup.find('title') else "Unknown Activity"
|
| 18 |
+
|
| 19 |
+
metrics = soup.find_all('div', class_='some-strava-metric-class') # Adjust based on Strava's page structure
|
| 20 |
+
activity_data = {
|
| 21 |
+
"title": title,
|
| 22 |
+
"metrics": [metric.text for metric in metrics] if metrics else ["No metrics found"]
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
return activity_data
|
| 26 |
+
|
| 27 |
+
# Hugging Face Model for Sentiment Analysis
|
| 28 |
+
sentiment_analyzer = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
| 29 |
+
|
| 30 |
+
# Function to analyze Strava activity description
|
| 31 |
+
def analyze_activity(url):
|
| 32 |
+
data = extract_activity_data(url)
|
| 33 |
+
if "title" in data:
|
| 34 |
+
analysis = sentiment_analyzer(data["title"])
|
| 35 |
+
return f"🏃 Activity: {data['title']}\n📊 Metrics: {', '.join(data['metrics'])}\n🔍 Analysis: {analysis}"
|
| 36 |
+
return "Error in fetching activity details."
|
| 37 |
+
|
| 38 |
+
# Gradio UI
|
| 39 |
+
iface = gr.Interface(
|
| 40 |
+
fn=analyze_activity,
|
| 41 |
+
inputs="text",
|
| 42 |
+
outputs="text",
|
| 43 |
+
title="🏅 Strava Activity Analyzer",
|
| 44 |
+
description="Paste your Strava activity link to analyze its details and performance insights!"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
iface.launch()
|