Update app.py
Browse files305 unmodified lines3063073083093103113122 unmodified lines315316317317318319320321322323324325326130 unmodified lines45745845946046146246346446546646746846947047147247347447522 unmodified lines498499500501502503504492505506507508509510496511512513514305 unmodified lines full_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 print processed_article = { "published_date": article["published_date"],2 unmodified lines "content": clean_content, "summary": full_summary, "cleaned_summary": cleaned_summary, "relevance_score": relevance_score "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 lines df['summary'] = df['cleaned_summary'] df = df.drop(columns=['cleaned_summary']) # Remove the extra column # Ensure relevance_score is present and convert to float if 'relevance_score' not in df.columns: df['relevance_score'] = 0.0 else: df['relevance_score'] = df['relevance_score'].astype(float) # Reorder columns to put relevance_score after summary columns = ['published_date', 'title', 'url', 'content', 'summary', 'relevance_score'] df = df[columns] # Format relevance_score to display 2 decimal places df['relevance_score'] = df['relevance_score'].apply(lambda x: f"{x:.2f}") with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmp: excel_path = tmp.name df.to_excel(excel_path, index=False)22 unmodified lines chain = LLMChain(llm=model, prompt=prompt_template) response = chain.run(summary=summary) print(f"Raw relevance score response: {response}") # Debug print try: score = float(response.strip()) return min(max(score, 0.00), 1.00) # Ensure the score is between 0.00 and 1.00 final_score = min(max(score, 0.00), 1.00) # Ensure the score is between 0.00 and 1.00 print(f"Processed relevance score: {final_score}") # Debug print return final_score except ValueError: print(f"Error parsing relevance score: {response}") return 0.00 def ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss): global conversation_history
app.py+18-3