Sooteemon commited on
Commit
cc35bd9
·
verified ·
1 Parent(s): 6c4f0bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -8
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # app.py
2
  import streamlit as st
3
  import requests
4
  from transformers import pipeline
@@ -21,7 +20,6 @@ NEWS_API_URL = "https://newsapi.org/v2/everything"
21
  @st.cache_resource
22
  def load_model():
23
  try:
24
- # --- นี่คือส่วนที่แก้ไข ---
25
  print("Loading model: MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
26
  classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
27
  print("Model loaded successfully!")
@@ -122,7 +120,7 @@ def search_yahoo_news(keyword, max_articles=10):
122
  st.error(f"Yahoo Search Error: {e}")
123
  return []
124
 
125
- # --- 5. ฟังก์ชันวิเคราะห์ (เหมือนเดิม) ---
126
  def analyze_themes(news_list, model, labels):
127
  results = []
128
  if not model:
@@ -143,7 +141,7 @@ def analyze_themes(news_list, model, labels):
143
 
144
  return pd.DataFrame(results)
145
 
146
- # --- 6. UI (อัปเกรด: รวม 2 แหล่งข่าว) ---
147
  st.title("📰 News Theme Analyzer")
148
  st.markdown("Analyzes news from trusted sources (Reuters, Bloomberg, Yahoo...)")
149
 
@@ -157,11 +155,9 @@ if st.button("Analyze News"):
157
  else:
158
  with st.spinner(f"Fetching and analyzing news for '{topic}'..."):
159
 
160
- # 1. ดึงข่าวจาก 2 แหล่ง
161
  news_api = fetch_news_from_api(topic, API_KEY)
162
  news_yahoo = search_yahoo_news(topic)
163
 
164
- # 2. รวมข่าวและลบข่าวซ้ำ
165
  all_news = news_api + news_yahoo
166
  seen_titles = set()
167
  unique_news_items = []
@@ -177,7 +173,6 @@ if st.button("Analyze News"):
177
  if df.empty:
178
  st.warning("Analysis failed, though news was fetched. Check logs.")
179
  else:
180
- # 3. แสดงสรุป (เหมือนเดิม)
181
  st.subheader("📊 Theme Distribution Summary")
182
  theme_counts = df['theme'].value_counts()
183
  total_articles = len(df)
@@ -194,7 +189,6 @@ if st.button("Analyze News"):
194
  st.dataframe(pd.DataFrame(summary_data), use_container_width=True)
195
  st.markdown("---")
196
 
197
- # 4. แสดงข่าว (เหมือนเดิม)
198
  st.subheader(f"📰 Analysis Results (Found {len(df)} unique articles)")
199
 
200
  for index, row in df.iterrows():
 
 
1
  import streamlit as st
2
  import requests
3
  from transformers import pipeline
 
20
  @st.cache_resource
21
  def load_model():
22
  try:
 
23
  print("Loading model: MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
24
  classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
25
  print("Model loaded successfully!")
 
120
  st.error(f"Yahoo Search Error: {e}")
121
  return []
122
 
123
+ # --- 5. ฟังก์ชันวิเคราะห์ ---
124
  def analyze_themes(news_list, model, labels):
125
  results = []
126
  if not model:
 
141
 
142
  return pd.DataFrame(results)
143
 
144
+ # --- 6. UI ---
145
  st.title("📰 News Theme Analyzer")
146
  st.markdown("Analyzes news from trusted sources (Reuters, Bloomberg, Yahoo...)")
147
 
 
155
  else:
156
  with st.spinner(f"Fetching and analyzing news for '{topic}'..."):
157
 
 
158
  news_api = fetch_news_from_api(topic, API_KEY)
159
  news_yahoo = search_yahoo_news(topic)
160
 
 
161
  all_news = news_api + news_yahoo
162
  seen_titles = set()
163
  unique_news_items = []
 
173
  if df.empty:
174
  st.warning("Analysis failed, though news was fetched. Check logs.")
175
  else:
 
176
  st.subheader("📊 Theme Distribution Summary")
177
  theme_counts = df['theme'].value_counts()
178
  total_articles = len(df)
 
189
  st.dataframe(pd.DataFrame(summary_data), use_container_width=True)
190
  st.markdown("---")
191
 
 
192
  st.subheader(f"📰 Analysis Results (Found {len(df)} unique articles)")
193
 
194
  for index, row in df.iterrows():