Spaces:
Sleeping
Sleeping
App.py
Browse files# Your model repo
model_id = "globalbrandon/autotrainfriday1"
# 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()
App.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Your model repo
|
| 2 |
+
model_id = "Meylai/ai-model-tryout"
|
| 3 |
+
|
| 4 |
+
# Load pipeline (auto-detects type based on model)
|
| 5 |
+
classifier = pipeline("text-classification", model=model_id)
|
| 6 |
+
|
| 7 |
+
# Define prediction function
|
| 8 |
+
def predict(text):
|
| 9 |
+
try:
|
| 10 |
+
result = classifier(text)[0]
|
| 11 |
+
label = result["label"]
|
| 12 |
+
score = round(result["score"] * 100, 2)
|
| 13 |
+
return f"Prediction: {label} ({score}%)"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error: {str(e)}"
|
| 16 |
+
|
| 17 |
+
# Gradio interface
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=predict,
|
| 20 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter your text here..."),
|
| 21 |
+
outputs=gr.Textbox(label="Model Prediction"),
|
| 22 |
+
title="Text Classifier",
|
| 23 |
+
description="This app uses a Hugging Face AutoTrain model to classify text."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|
| 27 |
+
|