douglasgoodwin commited on
Commit
c499e4d
·
verified ·
1 Parent(s): 13054b8

more involved

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -1,12 +1,25 @@
1
  import gradio as gr
 
2
 
3
- # Load the model interface
4
- interface = gr.load("models/bhadresh-savani/distilbert-base-uncased-emotion")
5
 
6
- # Apply customizations
7
- interface.launch(
8
- title="CMACHINES | Emotion Detection with DistilBERT",
9
- description="This app uses the DistilBERT model fine-tuned for emotion detection. Enter any text to analyze its emotional content.",
 
 
 
 
 
 
 
 
 
 
 
 
10
  examples=[
11
  "I am so happy to see you!",
12
  "I'm really angry about what happened.",
@@ -14,4 +27,4 @@ interface.launch(
14
  "I'm worried about the upcoming exam.",
15
  "Fear is the mind-killer. I will face my fear."
16
  ]
17
- )
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the Hugging Face pipeline
5
+ classifier = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
6
 
7
+ def classify_emotion(text):
8
+ # Make predictions using the Hugging Face pipeline
9
+ predictions = classifier(text)
10
+ return {item["label"]: item["score"] for item in predictions}
11
+
12
+ # Create a custom Gradio interface with title, description, and examples
13
+ gr.Interface(
14
+ fn=classify_emotion,
15
+ inputs=gr.Textbox(
16
+ placeholder="Enter text to analyze...",
17
+ label="Input Text",
18
+ lines=4
19
+ ),
20
+ outputs=gr.JSON(), # Display results in JSON format
21
+ title="Emotion Detection with DistilBERT",
22
+ description="This app uses the DistilBERT model fine-tuned for emotion detection. Enter a piece of text to analyze its emotional content!",
23
  examples=[
24
  "I am so happy to see you!",
25
  "I'm really angry about what happened.",
 
27
  "I'm worried about the upcoming exam.",
28
  "Fear is the mind-killer. I will face my fear."
29
  ]
30
+ ).launch()