File size: 964 Bytes
9778ff0
 
e7075f5
9778ff0
e7075f5
 
 
ad90c3e
e7075f5
 
 
9778ff0
e7075f5
 
 
9778ff0
e7075f5
 
 
 
 
9778ff0
e7075f5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("willco-afk/my-model-name")
model = AutoModelForSequenceClassification.from_pretrained("willco-afk/my-model-name")

# Function to classify input text
def classify_text(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
    with torch.no_grad():
        logits = model(**inputs).logits
    predicted_class = logits.argmax().item()  # Get the predicted class
    return f"Predicted class: {predicted_class}"

# Create a Gradio interface with customized layout
demo = gr.Interface(fn=classify_text, 
                    inputs=gr.Textbox(label="Enter your text"), 
                    outputs=gr.Textbox(label="Prediction"),
                    live=True)  # This option allows live feedback as you type

# Launch the Gradio interface
demo.launch()