Spaces:
Sleeping
Sleeping
| #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() | |