manupawar6388 commited on
Commit
dfd7410
·
verified ·
1 Parent(s): b4abc6a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, render_template
2
+ from predict_emotion import load_resources, predict_emotion
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Load model and resources at startup
7
+ print("Loading model resources...")
8
+ model, tokenizer, classes = load_resources()
9
+
10
+ @app.route('/', methods=['GET', 'POST'])
11
+ def home():
12
+ prediction = None
13
+ confidence = None
14
+ user_input = ""
15
+
16
+ if request.method == 'POST':
17
+ user_input = request.form.get('text')
18
+ if user_input:
19
+ emotion, conf = predict_emotion(user_input, model, tokenizer, classes)
20
+ prediction = emotion
21
+ confidence = f"{conf * 100:.1f}%"
22
+
23
+ return render_template('index.html', prediction=prediction, confidence=confidence, user_input=user_input)
24
+
25
+ if __name__ == '__main__':
26
+ app.run(host='0.0.0.0', port=7860)