Spaces:
Sleeping
Sleeping
Download app.py from KeyarSrini/strava-activity-analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/KeyarSrini/strava-activity-analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/KeyarSrini/strava-activity-analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/KeyarSrini/strava-activity-analysis/resolve/main/app.py
1.66 kB
| import gradio as gr | |
| import requests | |
| from bs4 import BeautifulSoup | |
| from transformers import pipeline | |
| # Function to extract Strava activity details | |
| def extract_activity_data(url): | |
| headers = {'User-Agent': 'Mozilla/5.0'} | |
| response = requests.get(url, headers=headers) | |
| if response.status_code != 200: | |
| return "Failed to fetch activity details." | |
| soup = BeautifulSoup(response.text, 'html.parser') | |
| # Extract Title and Some Metrics (Modify as needed) | |
| title = soup.find('title').text if soup.find('title') else "Unknown Activity" | |
| metrics = soup.find_all('div', class_='some-strava-metric-class') # Adjust based on Strava's page structure | |
| activity_data = { | |
| "title": title, | |
| "metrics": [metric.text for metric in metrics] if metrics else ["No metrics found"] | |
| } | |
| return activity_data | |
| # Hugging Face Model for Sentiment Analysis | |
| sentiment_analyzer = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment") | |
| # Function to analyze Strava activity description | |
| def analyze_activity(url): | |
| data = extract_activity_data(url) | |
| if "title" in data: | |
| analysis = sentiment_analyzer(data["title"]) | |
| return f"๐ Activity: {data['title']}\n๐ Metrics: {', '.join(data['metrics'])}\n๐ Analysis: {analysis}" | |
| return "Error in fetching activity details." | |
| # Gradio UI | |
| iface = gr.Interface( | |
| fn=analyze_activity, | |
| inputs="text", | |
| outputs="text", | |
| title="๐ Strava Activity Analyzer", | |
| description="Paste your Strava activity link to analyze its details and performance insights!" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |