Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,23 @@
|
|
| 1 |
-
#
|
| 2 |
import streamlit as st
|
| 3 |
from guardian import fetch_headlines, fetch_full_article
|
|
|
|
| 4 |
|
| 5 |
-
st.
|
|
|
|
| 6 |
|
| 7 |
# Sidebar controls
|
| 8 |
-
section = st.sidebar.
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
articles = fetch_headlines(section, limit)
|
| 15 |
-
if not articles:
|
| 16 |
-
st.warning("No articles returned. Check your API key and section name.")
|
| 17 |
-
else:
|
| 18 |
-
# Display headlines
|
| 19 |
-
for idx, (headline, url) in enumerate(articles, start=1):
|
| 20 |
-
st.markdown(f"**{idx}. {headline}** \n{url}")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
-
st.error(f"
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import streamlit as st
|
| 3 |
from guardian import fetch_headlines, fetch_full_article
|
| 4 |
+
from memes import article_to_meme
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="The Meme York Times", layout="wide")
|
| 7 |
+
st.title("📰➡️ Meme York Times")
|
| 8 |
|
| 9 |
# Sidebar controls
|
| 10 |
+
section = st.sidebar.selectbox("Section", ["world", "technology", "science", "culture"])
|
| 11 |
+
num = st.sidebar.slider("Number of articles", 1, 10, 5)
|
| 12 |
|
| 13 |
+
with st.spinner("Fetching articles…"):
|
| 14 |
+
articles = fetch_headlines(section, num)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
for headline, url in articles:
|
| 17 |
+
st.markdown(f"**{headline}** \n[{url}]({url})")
|
| 18 |
+
try:
|
| 19 |
+
full_text = fetch_full_article(url)
|
| 20 |
+
meme_url = article_to_meme(full_text)
|
| 21 |
+
st.image(meme_url, use_column_width=True)
|
| 22 |
except Exception as e:
|
| 23 |
+
st.error(f"Error generating meme: {e}")
|