Pavan97 commited on
Commit
212fd6e
·
verified ·
1 Parent(s): a64063f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+ import spaces
5
+
6
+ # Using HF's InferenceClient to delegate computing to serverless API
7
+ client = InferenceClient(model="Pavan97/Emotion_analysis_2026")
8
+
9
+ # A dummy GPU-decorated function to satisfy Hugging Face ZeroGPU startup validation
10
+ @spaces.GPU
11
+ def dummy_gpu_function():
12
+ return "GPU check passed"
13
+
14
+ def analyze_emotions(text):
15
+ if not text.strip():
16
+ return "Please enter some text to analyze."
17
+
18
+ try:
19
+ # Query the serverless model endpoint
20
+ results = client.text_classification(text)
21
+ # Format as dictionary of {label: score}
22
+ return {res['label']: float(res['score']) for res in results}
23
+ except Exception as e:
24
+ return {"Error querying the model endpoint. Please ensure the model is loaded or try again shortly.": 0.0}
25
+
26
+ # Define Gradio Interface
27
+ demo = gr.Interface(
28
+ fn=analyze_emotions,
29
+ inputs=gr.Textbox(lines=3, placeholder="Enter text to analyze emotions...", label="Input Text"),
30
+ outputs=gr.Label(num_top_classes=5, label="Predicted Emotions"),
31
+ title="Emotion Analysis 2026 Demo",
32
+ description="Identify emotions present in text using the fine-tuned RoBERTa model 'Pavan97/Emotion_analysis_2026' via serverless Inference API.",
33
+ examples=
34
+ ["thanks a lot for watching the video. really appreciate it",
35
+ "I am so angry that they delayed the flight again!",
36
+ "Wow, that is absolutely fascinating! Tell me more."]
37
+
38
+ )
39
+
40
+ if __name__ == '__main__':
41
+ # Trigger dummy call once to initialize GPU runtime requirements check
42
+ try:
43
+ dummy_gpu_function()
44
+ except Exception:
45
+ pass
46
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ huggingface_hub
3
+ spaces