AnkitAI commited on
Commit
6f21f1b
·
verified ·
1 Parent(s): adc6ee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -48
app.py CHANGED
@@ -1,50 +1,3 @@
1
  import gradio as gr
2
- from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
- import torch
4
 
5
- # Load the model and tokenizer once during initialization
6
- model_name = "AnkitAI/deberta-xlarge-base-emotions-classifier"
7
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
-
10
- # Define the function to use the model for predictions
11
- def classify_emotion(text):
12
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
13
- outputs = model(**inputs)
14
- probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
15
- labels = ["joy", "anger", "sadness", "fear", "surprise", "love"] # Adjust based on the actual labels used by the model
16
- return {labels[i]: float(probs[0][i]) for i in range(len(labels))}
17
-
18
- # Validate the input
19
- def validate_input(text):
20
- if len(text.strip()) == 0:
21
- return "Please enter some text."
22
- return classify_emotion(text)
23
-
24
- # Define the Gradio interface
25
- interface = gr.Interface(
26
- fn=validate_input,
27
- inputs=gr.Textbox(lines=5, placeholder="Enter text here...", label="Input Text"),
28
- outputs=gr.Label(label="Predicted Emotion"),
29
- title="Emotion Classifier",
30
- description="Enter some text and let the model predict the emotion.",
31
- examples=["I am feeling great today!", "I am so sad and depressed.", "I am excited about the new project."],
32
- )
33
-
34
- # Add some custom CSS to improve the look and feel
35
- css = """
36
- body {
37
- background-color: #f8f9fa;
38
- font-family: Arial, sans-serif;
39
- }
40
- h1 {
41
- color: #007bff;
42
- }
43
- .gradio-container {
44
- border-radius: 10px;
45
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
46
- }
47
- """
48
-
49
- # Launch the Gradio app with custom CSS
50
- interface.launch(server_name="0.0.0.0", server_port=8080, inline=False, css=css)
 
1
  import gradio as gr
 
 
2
 
3
+ gr.load("models/AnkitAI/reviews-roberta-base-sentiment-analysis").launch()