Update
Browse files- Dockerfile +11 -0
- app.py +57 -0
- index.html +47 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY . /app
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
8 |
+
|
9 |
+
EXPOSE 5000
|
10 |
+
|
11 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
# Load the models
|
7 |
+
translator = pipeline("translation_en_to_fr", model="Mr-Vicky-01/Fine_tune_english_to_tamil")
|
8 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
+
|
11 |
+
# Define the functions
|
12 |
+
def translate_text(text):
|
13 |
+
result = translator(text)
|
14 |
+
return result[0]['translation_text']
|
15 |
+
|
16 |
+
def summarize_text(text):
|
17 |
+
result = summarizer(text)
|
18 |
+
return result[0]['summary_text']
|
19 |
+
|
20 |
+
def analyze_sentiment(text):
|
21 |
+
result = sentiment_analyzer(text)
|
22 |
+
label = result[0]['label']
|
23 |
+
score = round(result[0]['score'], 3)
|
24 |
+
if label == 'POSITIVE':
|
25 |
+
return 'Happy'
|
26 |
+
elif label == 'NEGATIVE':
|
27 |
+
return 'Unhappy'
|
28 |
+
return 'Neutral'
|
29 |
+
|
30 |
+
# Home route
|
31 |
+
@app.route('/')
|
32 |
+
def home():
|
33 |
+
return render_template('index.html')
|
34 |
+
|
35 |
+
# Translation route
|
36 |
+
@app.route('/translate', methods=['POST'])
|
37 |
+
def translate():
|
38 |
+
input_text = request.form['input_text']
|
39 |
+
translated_text = translate_text(input_text)
|
40 |
+
return render_template('index.html', translated_text=translated_text)
|
41 |
+
|
42 |
+
# Summarization route
|
43 |
+
@app.route('/summarize', methods=['POST'])
|
44 |
+
def summarize():
|
45 |
+
input_text = request.form['input_summary']
|
46 |
+
summary_text = summarize_text(input_text)
|
47 |
+
return render_template('index.html', summary_text=summary_text)
|
48 |
+
|
49 |
+
# Sentiment Analysis route
|
50 |
+
@app.route('/sentiment', methods=['POST'])
|
51 |
+
def sentiment():
|
52 |
+
input_text = request.form['input_sentiment']
|
53 |
+
sentiment_result = analyze_sentiment(input_text)
|
54 |
+
return render_template('index.html', sentiment_result=sentiment_result)
|
55 |
+
|
56 |
+
if __name__ == '__main__':
|
57 |
+
app.run(debug=True)
|
index.html
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Text Pipeline</title>
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<h1>Text Pipeline: Translation, Summarization, and Sentiment Analysis</h1>
|
10 |
+
|
11 |
+
<!-- Translation Section -->
|
12 |
+
<h2>Translation</h2>
|
13 |
+
<form method="POST" action="/translate">
|
14 |
+
<label for="input_text">Enter text for translation:</label>
|
15 |
+
<input type="text" id="input_text" name="input_text" required>
|
16 |
+
<button type="submit">Translate</button>
|
17 |
+
</form>
|
18 |
+
{% if translated_text %}
|
19 |
+
<h3>Translated Text:</h3>
|
20 |
+
<p>{{ translated_text }}</p>
|
21 |
+
{% endif %}
|
22 |
+
|
23 |
+
<!-- Summarization Section -->
|
24 |
+
<h2>Summarization</h2>
|
25 |
+
<form method="POST" action="/summarize">
|
26 |
+
<label for="input_summary">Enter text for summarization:</label>
|
27 |
+
<input type="text" id="input_summary" name="input_summary" required>
|
28 |
+
<button type="submit">Summarize</button>
|
29 |
+
</form>
|
30 |
+
{% if summary_text %}
|
31 |
+
<h3>Summarized Text:</h3>
|
32 |
+
<p>{{ summary_text }}</p>
|
33 |
+
{% endif %}
|
34 |
+
|
35 |
+
<!-- Sentiment Analysis Section -->
|
36 |
+
<h2>Sentiment Analysis</h2>
|
37 |
+
<form method="POST" action="/sentiment">
|
38 |
+
<label for="input_sentiment">Enter text for sentiment analysis:</label>
|
39 |
+
<input type="text" id="input_sentiment" name="input_sentiment" required>
|
40 |
+
<button type="submit">Analyze Sentiment</button>
|
41 |
+
</form>
|
42 |
+
{% if sentiment_result %}
|
43 |
+
<h3>Sentiment Analysis Result:</h3>
|
44 |
+
<p>{{ sentiment_result }}</p>
|
45 |
+
{% endif %}
|
46 |
+
</body>
|
47 |
+
</html>
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
sentencepiece
|