Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -260,7 +260,15 @@ def summarize_news_content(content, model):
|
|
260 |
"""
|
261 |
prompt = ChatPromptTemplate.from_template(prompt_template)
|
262 |
formatted_prompt = prompt.format(content=content)
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
return summary
|
265 |
|
266 |
def process_google_news_rss(query, temperature, top_p, repetition_penalty):
|
@@ -275,18 +283,19 @@ def process_google_news_rss(query, temperature, top_p, repetition_penalty):
|
|
275 |
|
276 |
for article in articles:
|
277 |
try:
|
278 |
-
|
|
|
|
|
279 |
processed_article = {
|
280 |
"published_date": article["published_date"],
|
281 |
"title": article["title"],
|
282 |
"url": article["url"],
|
283 |
-
"content":
|
284 |
"summary": summary
|
285 |
}
|
286 |
processed_articles.append(processed_article)
|
287 |
except Exception as e:
|
288 |
-
print(f"Error processing article: {str(e)}")
|
289 |
-
|
290 |
if not processed_articles:
|
291 |
return "Failed to process any news articles. Please try a different query or check the summarization process."
|
292 |
|
|
|
260 |
"""
|
261 |
prompt = ChatPromptTemplate.from_template(prompt_template)
|
262 |
formatted_prompt = prompt.format(content=content)
|
263 |
+
full_response = generate_chunked_response(model, formatted_prompt, max_tokens=200)
|
264 |
+
|
265 |
+
# Extract only the summary part
|
266 |
+
summary_parts = full_response.split("Assistant:")
|
267 |
+
if len(summary_parts) > 1:
|
268 |
+
summary = summary_parts[-1].strip()
|
269 |
+
else:
|
270 |
+
summary = full_response.strip()
|
271 |
+
|
272 |
return summary
|
273 |
|
274 |
def process_google_news_rss(query, temperature, top_p, repetition_penalty):
|
|
|
283 |
|
284 |
for article in articles:
|
285 |
try:
|
286 |
+
# Remove HTML tags from content
|
287 |
+
clean_content = BeautifulSoup(article["content"], "html.parser").get_text()
|
288 |
+
summary = summarize_news_content(clean_content, model)
|
289 |
processed_article = {
|
290 |
"published_date": article["published_date"],
|
291 |
"title": article["title"],
|
292 |
"url": article["url"],
|
293 |
+
"content": clean_content,
|
294 |
"summary": summary
|
295 |
}
|
296 |
processed_articles.append(processed_article)
|
297 |
except Exception as e:
|
298 |
+
print(f"Error processing article: {str(e)}")
|
|
|
299 |
if not processed_articles:
|
300 |
return "Failed to process any news articles. Please try a different query or check the summarization process."
|
301 |
|