sayem ahmed shayeed commited on
Commit
c62f18d
·
verified ·
1 Parent(s): 5054abf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -1,14 +1,26 @@
 
1
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
2
 
 
3
  model_name = "shayeedahmed/psyche-bert-emotion-classifier"
4
-
5
- # Load tokenizer and model
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
 
 
 
 
 
8
 
9
- # Create a pipeline
10
- classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
 
 
 
 
 
 
11
 
12
- # Test
13
- result = classifier("Hello, how are you?")
14
- print(result)
 
1
+ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
3
 
4
+ # Load model
5
  model_name = "shayeedahmed/psyche-bert-emotion-classifier"
 
 
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
9
+
10
+ # Define inference function
11
+ def classify_text(text):
12
+ result = nlp(text)
13
+ return result
14
 
15
+ # Gradio interface
16
+ iface = gr.Interface(
17
+ fn=classify_text,
18
+ inputs=gr.Textbox(label="Enter text here"),
19
+ outputs=gr.JSON(label="Prediction"),
20
+ title="Emotion Classifier",
21
+ description="Classifies text into emotions"
22
+ )
23
 
24
+ # Launch the app (this is mandatory!)
25
+ if __name__ == "__main__":
26
+ iface.launch()