Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,41 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# Define the function to use the model for predictions
|
4 |
+
def classify_emotion(text):
|
5 |
+
model = gr.Interface.load("models/AnkitAI/deberta-xlarge-base-emotions-classifier")
|
6 |
+
return model(text)
|
7 |
+
|
8 |
+
# Validate the input
|
9 |
+
def validate_input(text):
|
10 |
+
if len(text.strip()) == 0:
|
11 |
+
return "Please enter some text."
|
12 |
+
return classify_emotion(text)
|
13 |
+
|
14 |
+
# Define the Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=validate_input,
|
17 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter text here...", label="Input Text"),
|
18 |
+
outputs=gr.Label(label="Predicted Emotion"),
|
19 |
+
title="Emotion Classifier",
|
20 |
+
description="Enter some text and let the model predict the emotion.",
|
21 |
+
examples=["I am feeling great today!", "I am so sad and depressed.", "I am excited about the new project."],
|
22 |
+
theme="huggingface"
|
23 |
+
)
|
24 |
+
|
25 |
+
# Add some custom CSS to improve the look and feel
|
26 |
+
css = """
|
27 |
+
body {
|
28 |
+
background-color: #f8f9fa;
|
29 |
+
font-family: Arial, sans-serif;
|
30 |
+
}
|
31 |
+
h1 {
|
32 |
+
color: #007bff;
|
33 |
+
}
|
34 |
+
.gradio-container {
|
35 |
+
border-radius: 10px;
|
36 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
37 |
+
}
|
38 |
+
"""
|
39 |
+
|
40 |
+
# Launch the Gradio app with custom CSS
|
41 |
+
interface.launch(server_name="0.0.0.0", server_port=8080, inline=False, css=css)
|