File size: 865 Bytes
876c376
951b188
876c376
951b188
 
 
de2c4ff
951b188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de2c4ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer

# Load model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("rabiaqayyum/autotrain-mental-health-analysis-752423172")
tokenizer = AutoTokenizer.from_pretrained("rabiaqayyum/autotrain-mental-health-analysis-752423172")

# Define function to process inputs and get predictions
def predict(text):
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
    outputs = model(**inputs)
    predicted_class = outputs.logits.argmax().item()
    return "Positive" if predicted_class == 1 else "Negative"

# Create Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs="text",
    outputs="text",
    layout="vertical",
    description="Enter text to get model predictions."
)

# Launch the interface
iface.launch()