update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,31 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
# Pipeline
|
| 5 |
-
pipe = pipeline("text-classification", model="AbrorBalxiyev/my_awesome_model")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def classify_text(text):
|
| 9 |
-
results = pipe(text)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
gr.Markdown("## Text Classification Pipeline")
|
| 16 |
-
text_input = gr.Textbox(label="Enter Text", placeholder="Type something here...")
|
| 17 |
-
output_label = gr.Label(label="Classification Results")
|
| 18 |
-
classify_button = gr.Button("Classify")
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
|
| 4 |
+
# Pipeline
|
| 5 |
+
pipe = pipeline("text-classification", model="AbrorBalxiyev/my_awesome_model", return_all_scores=True)
|
| 6 |
|
| 7 |
+
# Gradio interfeysi uchun funksiyani qayta yozish
|
| 8 |
def classify_text(text):
|
| 9 |
+
results = pipe(text)[0]
|
| 10 |
+
results.sort(key=lambda x: x["score"], reverse=True)
|
| 11 |
+
result = ""
|
| 12 |
+
for item in results:
|
| 13 |
+
percentage = item["score"] * 100
|
| 14 |
+
result += f"{item['label']}: {percentage:.1f}%\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
return result
|
| 17 |
+
# Gradio interfeysi
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=classify_text,
|
| 20 |
+
inputs=gr.Textbox(placeholder="Enter text to classify...", label="Input Text"),
|
| 21 |
+
outputs=gr.Textbox(label="Classification Results"),
|
| 22 |
+
title="Text Category Classification",
|
| 23 |
+
description="Enter text to see its category classification percentages.",
|
| 24 |
+
examples=[
|
| 25 |
+
["Mercedes is one of the best quality cars."],
|
| 26 |
+
["Perevalda Damas va Lacetti avtomobillari avtoxalokatga uchradi"],
|
| 27 |
+
["Kitob o'qish foydali"]
|
| 28 |
+
]
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
iface.launch()
|
|
|