from flask import Flask, render_template, request from transformers import pipeline app = Flask(__name__) # Load the models translator = pipeline("translation_en_to_fr", model="Mr-Vicky-01/Fine_tune_english_to_tamil") sentiment_analyzer = pipeline("sentiment-analysis") summarizer = pipeline("summarization", model="facebook/bart-large-cnn") # Define the functions def translate_text(text): result = translator(text) return result[0]['translation_text'] def summarize_text(text): result = summarizer(text) return result[0]['summary_text'] def analyze_sentiment(text): result = sentiment_analyzer(text) label = result[0]['label'] score = round(result[0]['score'], 3) if label == 'POSITIVE': return 'Happy' elif label == 'NEGATIVE': return 'Unhappy' return 'Neutral' # Home route @app.route('/') def home(): return render_template('index.html') # Translation route @app.route('/translate', methods=['POST']) def translate(): input_text = request.form['input_text'] translated_text = translate_text(input_text) return render_template('index.html', translated_text=translated_text) # Summarization route @app.route('/summarize', methods=['POST']) def summarize(): input_text = request.form['input_summary'] summary_text = summarize_text(input_text) return render_template('index.html', summary_text=summary_text) # Sentiment Analysis route @app.route('/sentiment', methods=['POST']) def sentiment(): input_text = request.form['input_sentiment'] sentiment_result = analyze_sentiment(input_text) return render_template('index.html', sentiment_result=sentiment_result) if __name__ == '__main__': app.run(debug=True)