faizan20 commited on
Commit
96993d4
·
verified ·
1 Parent(s): c46e765

changed filename gradio_app.py to app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ API_URL = "http://127.0.0.1:8000/api/predict"
5
+
6
+ def analyze_text(text):
7
+ try:
8
+ response = requests.post(API_URL, json={"text": text})
9
+ if response.status_code == 200:
10
+ result = response.json()
11
+ sentiment = result.get("sentiment", "")
12
+ emotion = result.get("emotion", "")
13
+ return f"➡️ **Sentiment:** {sentiment}\n\n ➡️ **Emotion:** {emotion}"
14
+ else:
15
+ return f"API Error: {response.status_code}"
16
+ except Exception as e:
17
+ return f"Error connecting to API: {str(e)}"
18
+
19
+ custom_css = """
20
+ .gradio-container {
21
+ background: linear-gradient(135deg, #e9f1fc 0%, #fefefe 100%);
22
+ font-family: 'Segoe UI', Roboto, sans-serif;
23
+ }
24
+ h1 {
25
+ text-align: center !important;
26
+ font-size: 2.2rem !important;
27
+ color: #1f2937 !important;
28
+ font-weight: 600 !important;
29
+ }
30
+ textarea, .output_text {
31
+ font-size: 1.1rem !important;
32
+ line-height: 1.6 !important;
33
+ }
34
+ .output_text {
35
+ background: #f9fafb !important;
36
+ border-radius: 12px !important;
37
+ padding: 16px !important;
38
+ border: 1px solid #e5e7eb !important;
39
+ }
40
+ """
41
+
42
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
43
+ gr.Markdown("# 💬 Emotion & Sentiment Analyzer")
44
+ gr.Markdown("### Type your text below to discover its emotional tone and sentiment ✨")
45
+
46
+ with gr.Row():
47
+ text_input = gr.Textbox(
48
+ label="Enter text here",
49
+ placeholder="e.g. I'm so excited to work on this project!",
50
+ lines=4,
51
+ scale=2
52
+ )
53
+ with gr.Row():
54
+ output_box = gr.Markdown(label="Results", elem_classes="output_text")
55
+
56
+ analyze_button = gr.Button("🔍 Analyze", variant="primary")
57
+
58
+ analyze_button.click(fn=analyze_text, inputs=text_input, outputs=output_box)
59
+
60
+ demo.launch()