rushankg commited on
Commit
a0ed106
·
verified ·
1 Parent(s): faca1ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -1,28 +1,23 @@
1
- # test_app.py
2
  import streamlit as st
3
  from guardian import fetch_headlines, fetch_full_article
 
4
 
5
- st.title("🧪 Guardian API Test")
 
6
 
7
  # Sidebar controls
8
- section = st.sidebar.text_input("Section", "world")
9
- limit = st.sidebar.number_input("Number of articles", min_value=1, max_value=10, value=3, step=1)
10
 
11
- if st.sidebar.button("Run Test"):
12
- st.write(f"Fetching up to {limit} articles from section '{section}'…")
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
- # Fetch full text for the first article
23
- first_title, first_url = articles[0]
24
- st.markdown(f"### Full text of “{first_title}”")
25
- body = fetch_full_article(first_url)
26
- st.text_area("Article Body", body, height=300)
 
27
  except Exception as e:
28
- st.error(f" Guardian API error: {e}")
 
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}")