Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -306,6 +306,7 @@ def process_news(query, temperature, top_p, repetition_penalty, news_source):
|
|
306 |
|
307 |
full_summary, cleaned_summary = summarize_news_content(clean_content, model)
|
308 |
relevance_score = calculate_relevance_score(cleaned_summary, model)
|
|
|
309 |
|
310 |
processed_article = {
|
311 |
"published_date": article["published_date"],
|
@@ -314,11 +315,12 @@ def process_news(query, temperature, top_p, repetition_penalty, news_source):
|
|
314 |
"content": clean_content,
|
315 |
"summary": full_summary,
|
316 |
"cleaned_summary": cleaned_summary,
|
317 |
-
"relevance_score": relevance_score
|
318 |
}
|
319 |
processed_articles.append(processed_article)
|
320 |
except Exception as e:
|
321 |
print(f"Error processing article: {str(e)}")
|
|
|
322 |
|
323 |
if not processed_articles:
|
324 |
return f"Failed to process any news articles from {news_source}. Please try again or check the summarization process."
|
@@ -455,10 +457,19 @@ def export_news_to_excel():
|
|
455 |
df['summary'] = df['cleaned_summary']
|
456 |
df = df.drop(columns=['cleaned_summary']) # Remove the extra column
|
457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
# Reorder columns to put relevance_score after summary
|
459 |
columns = ['published_date', 'title', 'url', 'content', 'summary', 'relevance_score']
|
460 |
df = df[columns]
|
461 |
|
|
|
|
|
|
|
462 |
with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp:
|
463 |
excel_path = tmp.name
|
464 |
df.to_excel(excel_path, index=False)
|
@@ -487,13 +498,17 @@ def calculate_relevance_score(summary, model):
|
|
487 |
chain = LLMChain(llm=model, prompt=prompt_template)
|
488 |
response = chain.run(summary=summary)
|
489 |
|
|
|
|
|
490 |
try:
|
491 |
score = float(response.strip())
|
492 |
-
|
|
|
|
|
493 |
except ValueError:
|
494 |
print(f"Error parsing relevance score: {response}")
|
495 |
return 0.00
|
496 |
-
|
497 |
def ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss):
|
498 |
global conversation_history
|
499 |
|
|
|
306 |
|
307 |
full_summary, cleaned_summary = summarize_news_content(clean_content, model)
|
308 |
relevance_score = calculate_relevance_score(cleaned_summary, model)
|
309 |
+
print(f"Relevance score for article '{article['title']}': {relevance_score}") # Debug print
|
310 |
|
311 |
processed_article = {
|
312 |
"published_date": article["published_date"],
|
|
|
315 |
"content": clean_content,
|
316 |
"summary": full_summary,
|
317 |
"cleaned_summary": cleaned_summary,
|
318 |
+
"relevance_score": relevance_score # Ensure this line is present
|
319 |
}
|
320 |
processed_articles.append(processed_article)
|
321 |
except Exception as e:
|
322 |
print(f"Error processing article: {str(e)}")
|
323 |
+
|
324 |
|
325 |
if not processed_articles:
|
326 |
return f"Failed to process any news articles from {news_source}. Please try again or check the summarization process."
|
|
|
457 |
df['summary'] = df['cleaned_summary']
|
458 |
df = df.drop(columns=['cleaned_summary']) # Remove the extra column
|
459 |
|
460 |
+
# Ensure relevance_score is present and convert to float
|
461 |
+
if 'relevance_score' not in df.columns:
|
462 |
+
df['relevance_score'] = 0.0
|
463 |
+
else:
|
464 |
+
df['relevance_score'] = df['relevance_score'].astype(float)
|
465 |
+
|
466 |
# Reorder columns to put relevance_score after summary
|
467 |
columns = ['published_date', 'title', 'url', 'content', 'summary', 'relevance_score']
|
468 |
df = df[columns]
|
469 |
|
470 |
+
# Format relevance_score to display 2 decimal places
|
471 |
+
df['relevance_score'] = df['relevance_score'].apply(lambda x: f"{x:.2f}")
|
472 |
+
|
473 |
with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp:
|
474 |
excel_path = tmp.name
|
475 |
df.to_excel(excel_path, index=False)
|
|
|
498 |
chain = LLMChain(llm=model, prompt=prompt_template)
|
499 |
response = chain.run(summary=summary)
|
500 |
|
501 |
+
print(f"Raw relevance score response: {response}") # Debug print
|
502 |
+
|
503 |
try:
|
504 |
score = float(response.strip())
|
505 |
+
final_score = min(max(score, 0.00), 1.00) # Ensure the score is between 0.00 and 1.00
|
506 |
+
print(f"Processed relevance score: {final_score}") # Debug print
|
507 |
+
return final_score
|
508 |
except ValueError:
|
509 |
print(f"Error parsing relevance score: {response}")
|
510 |
return 0.00
|
511 |
+
|
512 |
def ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss):
|
513 |
global conversation_history
|
514 |
|