File size: 1,898 Bytes
96993d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
import requests

API_URL = "http://127.0.0.1:8000/api/predict"

def analyze_text(text):
    try:
        response = requests.post(API_URL, json={"text": text})
        if response.status_code == 200:
            result = response.json()
            sentiment = result.get("sentiment", "")
            emotion = result.get("emotion", "")
            return f"➡️ **Sentiment:** {sentiment}\n\n ➡️ **Emotion:** {emotion}"
        else:
            return f"API Error: {response.status_code}"
    except Exception as e:
        return f"Error connecting to API: {str(e)}"

custom_css = """

.gradio-container {

    background: linear-gradient(135deg, #e9f1fc 0%, #fefefe 100%);

    font-family: 'Segoe UI', Roboto, sans-serif;

}

h1 {

    text-align: center !important;

    font-size: 2.2rem !important;

    color: #1f2937 !important;

    font-weight: 600 !important;

}

textarea, .output_text {

    font-size: 1.1rem !important;

    line-height: 1.6 !important;

}

.output_text {

    background: #f9fafb !important;

    border-radius: 12px !important;

    padding: 16px !important;

    border: 1px solid #e5e7eb !important;

}

"""

with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 💬 Emotion & Sentiment Analyzer")
    gr.Markdown("### Type your text below to discover its emotional tone and sentiment ✨")

    with gr.Row():
        text_input = gr.Textbox(
            label="Enter text here",
            placeholder="e.g. I'm so excited to work on this project!",
            lines=4,
            scale=2
        )
    with gr.Row():
        output_box = gr.Markdown(label="Results", elem_classes="output_text")

    analyze_button = gr.Button("🔍 Analyze", variant="primary")

    analyze_button.click(fn=analyze_text, inputs=text_input, outputs=output_box)

demo.launch()