Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load your model from Hugging Face
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="username/model-name", # Replace with your Hugging Face username/model
|
| 8 |
+
tokenizer="username/model-name", # Same here
|
| 9 |
+
top_k=None # Return all labels with scores
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Define the prediction function
|
| 13 |
+
def classify_numbers(n1, n2, n3):
|
| 14 |
+
input_str = f"{n1}, {n2}, {n3}"
|
| 15 |
+
result = classifier(input_str)
|
| 16 |
+
# Format the results nicely
|
| 17 |
+
output = {item["label"]: round(item["score"], 3) for item in result[0]}
|
| 18 |
+
return output
|
| 19 |
+
|
| 20 |
+
# Create Gradio interface
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=classify_numbers,
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Textbox(label="Input 1"),
|
| 25 |
+
gr.Textbox(label="Input 2"),
|
| 26 |
+
gr.Textbox(label="Input 3")
|
| 27 |
+
],
|
| 28 |
+
outputs="label",
|
| 29 |
+
title="Number Classifier",
|
| 30 |
+
description="Enter 3 numbers or symbols (e.g., 3.14, pi, 2) to classify them."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
iface.launch()
|