rishabh5752 commited on
Commit
951b188
1 Parent(s): 9cc34de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -1,7 +1,25 @@
1
  import gradio as gr
 
2
 
3
- # Define the Gradio interface using the model you mentioned
4
- iface = gr.Interface.load("rabiaqayyum/autotrain-mental-health-analysis-752423172")
 
5
 
6
- # Launch the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
 
4
+ # Load model and tokenizer
5
+ model = AutoModelForSequenceClassification.from_pretrained("rabiaqayyum/autotrain-mental-health-analysis-752423172")
6
+ tokenizer = AutoTokenizer.from_pretrained("rabiaqayyum/autotrain-mental-health-analysis-752423172")
7
 
8
+ # Define function to process inputs and get predictions
9
+ def predict(text):
10
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
11
+ outputs = model(**inputs)
12
+ predicted_class = outputs.logits.argmax().item()
13
+ return "Positive" if predicted_class == 1 else "Negative"
14
+
15
+ # Create Gradio interface
16
+ iface = gr.Interface(
17
+ fn=predict,
18
+ inputs="text",
19
+ outputs="text",
20
+ layout="vertical",
21
+ description="Enter text to get model predictions."
22
+ )
23
+
24
+ # Launch the interface
25
  iface.launch()