Spaces:
Sleeping
Sleeping
File size: 842 Bytes
38de84d 0b60f86 e47d61e 0b60f86 | 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 27 28 29 30 31 32 | #import required libraries
from transformers import pipeline
import gradio as gr
# Your model repo
model_id = "Meylai/ai-model-try-out"
# Load pipeline (auto-detects type based on model)
classifier = pipeline("text-classification", model=model_id)
# Define prediction function
def predict(text):
try:
result = classifier(text)[0]
label = result["label"]
score = round(result["score"] * 100, 2)
return f"Prediction: {label} ({score}%)"
except Exception as e:
return f"Error: {str(e)}"
# Gradio interface
demo = gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=4, placeholder="Enter your text here..."),
outputs=gr.Textbox(label="Model Prediction"),
title="Text Classifier",
description="This app uses a Hugging Face AutoTrain model to classify text."
)
demo.launch()
|