Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,28 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
# Initialize a text generation pipeline
|
| 7 |
generator = pipeline('text-generation', model='dbmdz/german-gpt2')
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
params = {
|
| 14 |
-
"q": topic,
|
| 15 |
-
"apiKey": api_key,
|
| 16 |
-
"language": "en",
|
| 17 |
-
"sortBy": "relevancy",
|
| 18 |
-
"pageSize": max_items
|
| 19 |
-
}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"source": article["source"]["name"],
|
| 32 |
-
"publishedAt": article["publishedAt"],
|
| 33 |
-
"url": article["url"]
|
| 34 |
-
}
|
| 35 |
-
formatted_articles.append(formatted_article)
|
| 36 |
-
|
| 37 |
-
return formatted_articles
|
| 38 |
-
except requests.RequestException as e:
|
| 39 |
-
st.error(f"Error fetching news data: {e}")
|
| 40 |
-
return []
|
| 41 |
|
| 42 |
-
# Define the
|
| 43 |
def page_trending_niche():
|
| 44 |
-
api_key = "YOUR_API_KEY_HERE" # Securely fetch your API key
|
| 45 |
-
|
| 46 |
col1, col2 = st.columns([3, 1])
|
| 47 |
with col1:
|
| 48 |
st.title("What is trending in my niche?")
|
|
@@ -51,16 +31,12 @@ def page_trending_niche():
|
|
| 51 |
|
| 52 |
niche = st.text_input('Enter your niche', 'German clinics')
|
| 53 |
if niche:
|
| 54 |
-
news_items =
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
st.write(f"**URL:** [Read more]({item['url']})")
|
| 61 |
-
st.write("---")
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from pygooglenews import GoogleNews
|
|
|
|
| 4 |
|
| 5 |
# Initialize a text generation pipeline
|
| 6 |
generator = pipeline('text-generation', model='dbmdz/german-gpt2')
|
| 7 |
|
| 8 |
+
# Function to fetch top stories related to a specific topic
|
| 9 |
+
def fetch_top_stories(topic, language='de', country='GER'):
|
| 10 |
+
gn = GoogleNews(lang=language, country=country)
|
| 11 |
+
search_results = gn.search(topic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
top_stories = []
|
| 14 |
+
for story in search_results['entries']:
|
| 15 |
+
story_data = {
|
| 16 |
+
'title': story.title,
|
| 17 |
+
'link': story.link,
|
| 18 |
+
'published': story.published
|
| 19 |
+
}
|
| 20 |
+
top_stories.append(story_data)
|
| 21 |
+
|
| 22 |
+
return top_stories
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# Define the page for trending niche news
|
| 25 |
def page_trending_niche():
|
|
|
|
|
|
|
| 26 |
col1, col2 = st.columns([3, 1])
|
| 27 |
with col1:
|
| 28 |
st.title("What is trending in my niche?")
|
|
|
|
| 31 |
|
| 32 |
niche = st.text_input('Enter your niche', 'German clinics')
|
| 33 |
if niche:
|
| 34 |
+
news_items = fetch_top_stories(niche)
|
| 35 |
+
for item in news_items:
|
| 36 |
+
st.write(f"**Title:** {item['title']}")
|
| 37 |
+
st.write(f"**Link:** [Read more]({item['link']})")
|
| 38 |
+
st.write(f"**Published:** {item['published']}")
|
| 39 |
+
st.write("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
|