Priyanshuchaudhary2425 commited on
Commit
aad95e2
1 Parent(s): 7ecc7a6

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "Priyanshuchaudhary2425/EmotiNet"
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Class list
10
+ class_list = ['sadness', 'joy', 'love', 'anger', 'fear', 'surprise']
11
+
12
+ # Define the function to make predictions with your model
13
+ def predict_emotion(text):
14
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
15
+ outputs = model(**inputs)
16
+ probabilities = outputs.logits.softmax(dim=1).tolist()[0]
17
+ return {class_list[label]: probability for label, probability in enumerate(probabilities)}
18
+
19
+ # Create a Gradio interface for your model
20
+ output_probabilities = gr.Label(num_top_classes=6)
21
+
22
+ interface = gr.Interface(
23
+ fn=predict_emotion,
24
+ inputs=gr.Textbox(lines=5, label="Enter your text here"),
25
+ outputs=output_probabilities,
26
+ title="Emotion Detection",
27
+ description="This model predicts the probabilities of different emotions (sadness, joy, love, anger, fear, surprise) based on the input text.",
28
+ examples=[
29
+ ["In her warm embrace, I found solace, a refuge from the chaos of the world. Every beat of her heart echoed the melody of love, drawing me closer with each tender touch."],
30
+ ["Fury surged through my veins, a tempest of resentment and indignation, fueled by the betrayal of trust. In that moment, every word spoken was a dagger, piercing through the facade of civility."],
31
+ ["Tears silently traced their path down my cheeks, carrying the weight of unspoken sorrows, each drop a testament to the pain within. In the quiet of the night, I grappled with the emptiness that engulfed my soul, longing for the light of hope to pierce through the darkness."]
32
+ ]
33
+ )
34
+
35
+ # Launch the Gradio interface with sharing enabled
36
+ interface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.13.0
2
+ transformers==4.37.1