Update app.py
Browse files305 unmodified lines3063073083093103112 unmodified lines314315316317318319320321322323324130 unmodified lines45545645745845946046146246346422 unmodified lines487488489490491492493494495496497498499305 unmodified linesfull_summary, cleaned_summary = summarize_news_content(clean_content, model)relevance_score = calculate_relevance_score(cleaned_summary, model)processed_article = {"published_date": article["published_date"],2 unmodified lines"content": clean_content,"summary": full_summary,"cleaned_summary": cleaned_summary,"relevance_score": relevance_score}processed_articles.append(processed_article)except Exception as e:print(f"Error processing article: {str(e)}")if not processed_articles:return f"Failed to process any news articles from {news_source}. Please try again or check the summarization process."130 unmodified linesdf['summary'] = df['cleaned_summary']df = df.drop(columns=['cleaned_summary']) # Remove the extra column# Reorder columns to put relevance_score after summarycolumns = ['published_date', 'title', 'url', 'content', 'summary', 'relevance_score']df = df[columns]with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp:excel_path = tmp.namedf.to_excel(excel_path, index=False)22 unmodified lineschain = LLMChain(llm=model, prompt=prompt_template)response = chain.run(summary=summary)try:score = float(response.strip())return min(max(score, 0.00), 1.00) # Ensure the score is between 0.00 and 1.00except ValueError:print(f"Error parsing relevance score: {response}")return 0.00def ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss):global conversation_history305 unmodified lines3063073083093103113122 unmodified lines315316317318319320321322323324325326130 unmodified lines45745845946046146246346446546646746846947047147247347447522 unmodified lines498499500501502503504505506507508509510511512513514305 unmodified linesfull_summary, cleaned_summary = summarize_news_content(clean_content, model)relevance_score = calculate_relevance_score(cleaned_summary, model)print(f"Relevance score for article '{article['title']}': {relevance_score}") # Debug printprocessed_article = {"published_date": article["published_date"],2 unmodified lines"content": clean_content,"summary": full_summary,"cleaned_summary": cleaned_summary,"relevance_score": relevance_score # Ensure this line is present}processed_articles.append(processed_article)except Exception as e:print(f"Error processing article: {str(e)}")if not processed_articles:return f"Failed to process any news articles from {news_source}. Please try again or check the summarization process."130 unmodified linesdf['summary'] = df['cleaned_summary']df = df.drop(columns=['cleaned_summary']) # Remove the extra column# Ensure relevance_score is present and convert to floatif 'relevance_score' not in df.columns:df['relevance_score'] = 0.0else:df['relevance_score'] = df['relevance_score'].astype(float)# Reorder columns to put relevance_score after summarycolumns = ['published_date', 'title', 'url', 'content', 'summary', 'relevance_score']df = df[columns]# Format relevance_score to display 2 decimal placesdf['relevance_score'] = df['relevance_score'].apply(lambda x: f"{x:.2f}")with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp:excel_path = tmp.namedf.to_excel(excel_path, index=False)22 unmodified lineschain = LLMChain(llm=model, prompt=prompt_template)response = chain.run(summary=summary)print(f"Raw relevance score response: {response}") # Debug printtry:score = float(response.strip())final_score = min(max(score, 0.00), 1.00) # Ensure the score is between 0.00 and 1.00print(f"Processed relevance score: {final_score}") # Debug printreturn final_scoreexcept ValueError:print(f"Error parsing relevance score: {response}")return 0.00def ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss):global conversation_history
app.py+18-3