Spaces:
Sleeping
Sleeping
| from flask import Flask, request, jsonify, send_from_directory | |
| from utils import fetch_news_links, summarize_text, analyze_sentiment, extract_topics, generate_hindi_tts | |
| app = Flask(__name__) | |
| def get_news(): | |
| """Fetches news articles and generates TTS.""" | |
| company = request.args.get('company') | |
| if not company: | |
| return jsonify({"error": "Company name is required"}), 400 | |
| articles = fetch_news_links(company) | |
| if not articles: | |
| return jsonify({"error": "No news articles found for this company."}), 404 | |
| processed_articles = [ | |
| { | |
| "Title": article["Title"], | |
| "Summary": summarize_text(article["Content"]), | |
| "Sentiment": analyze_sentiment(article["Content"]), | |
| "Topics": extract_topics(article["Content"]), | |
| "URL": article["URL"] | |
| } | |
| for article in articles | |
| ] | |
| summary_text = " ".join([a["Summary"] for a in processed_articles]) | |
| audio_filename = generate_hindi_tts(summary_text, company) | |
| return jsonify({ | |
| "Company": company, | |
| "Articles": processed_articles, | |
| "Final Sentiment Analysis": "Overall sentiment is positive." if any(a["Sentiment"] == "Positive" for a in processed_articles) else "Overall sentiment is neutral or negative.", | |
| "AudioFile": f"/static/{audio_filename.split('/')[-1]}", # Return relative URL for client access | |
| "Status": "Processing Complete!" | |
| }) | |
| def serve_static(filename): | |
| """Serves static files like audio.""" | |
| return send_from_directory('static', filename) | |
| if __name__ == '__main__': | |
| print("API Running on http://127.0.0.1:5000") | |
| app.run(host='127.0.0.1', port=5000, debug=True, use_reloader=False) |