Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
# Load model and tokenizer
|
6 |
+
model_name = "" # Replace with your model's Hugging Face Hub path
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
+
# Define prediction function
|
11 |
+
def predict(text):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
13 |
+
with torch.no_grad():
|
14 |
+
outputs = model(**inputs)
|
15 |
+
logits = outputs.logits
|
16 |
+
prediction = torch.argmax(logits, dim=1).item()
|
17 |
+
return prediction
|
18 |
+
|
19 |
+
# Set up Gradio interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=predict,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text",
|
24 |
+
title="My Model Prediction",
|
25 |
+
description="Enter some text and see what the model predicts!"
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the Gradio app
|
29 |
+
if __name__ == "__main__":
|
30 |
+
interface.launch()
|