Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -124,27 +124,47 @@ def summarize_news(articles: List[Dict]) -> str:
|
|
124 |
content_to_summarize = ""
|
125 |
for article in articles:
|
126 |
content = article.get('full_content', article['snippet'])
|
127 |
-
content_to_summarize += f"Title: {article['title']}\nSource: {article['source']}\nContent: {content}\n\n"
|
128 |
|
129 |
# Use DeepSeek model to generate a concise summary
|
130 |
-
summary_prompt = f"""
|
131 |
|
132 |
-
Articles to summarize:
|
133 |
{content_to_summarize}
|
134 |
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
"""
|
142 |
|
143 |
try:
|
144 |
summary = deepseek_model.complete(summary_prompt).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
return summary
|
146 |
except Exception as e:
|
147 |
-
|
148 |
return original_summary_format(articles)
|
149 |
|
150 |
def original_summary_format(articles: List[Dict]) -> str:
|
|
|
124 |
content_to_summarize = ""
|
125 |
for article in articles:
|
126 |
content = article.get('full_content', article['snippet'])
|
127 |
+
content_to_summarize += f"Title: {article['title']}\nSource: {article['source']}\nDate: {article['date']}\nContent: {content}\n\n"
|
128 |
|
129 |
# Use DeepSeek model to generate a concise summary
|
130 |
+
summary_prompt = f"""Analyze these news articles and create a comprehensive yet concise summary:
|
131 |
|
|
|
132 |
{content_to_summarize}
|
133 |
|
134 |
+
Requirements:
|
135 |
+
1. Start with a 2-3 sentence overview of the main developments
|
136 |
+
2. Focus on concrete facts and important details
|
137 |
+
3. Maintain journalistic neutrality
|
138 |
+
4. Include relevant names, locations, and key figures
|
139 |
+
5. Organize related information together
|
140 |
|
141 |
+
Format the output exactly as follows:
|
142 |
+
📰 Summary:
|
143 |
+
[2-3 sentence overview of the main developments]
|
144 |
+
|
145 |
+
🔍 Key Developments:
|
146 |
+
• [First major development with specific details]
|
147 |
+
• [Second major development with specific details]
|
148 |
+
• [Additional developments if relevant]
|
149 |
+
|
150 |
+
📑 Articles:
|
151 |
+
1. [Article Title] ([Source], [Date])
|
152 |
+
[One-line highlight of the article's main point]
|
153 |
+
[Read more: link]
|
154 |
"""
|
155 |
|
156 |
try:
|
157 |
summary = deepseek_model.complete(summary_prompt).strip()
|
158 |
+
# Ensure links are properly formatted
|
159 |
+
for article in articles:
|
160 |
+
if article['link'] in summary:
|
161 |
+
summary = summary.replace(
|
162 |
+
f"[Read more: {article['link']}]",
|
163 |
+
f"[Read more]({article['link']})"
|
164 |
+
)
|
165 |
return summary
|
166 |
except Exception as e:
|
167 |
+
print(f"DeepSeek summarization failed: {str(e)}")
|
168 |
return original_summary_format(articles)
|
169 |
|
170 |
def original_summary_format(articles: List[Dict]) -> str:
|