AbrorBalxiyev
commited on
update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,56 @@
|
|
1 |
-
|
2 |
-
|
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 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=[
|
21 |
+
gr.Textbox(
|
22 |
+
placeholder="Enter text to classify...",
|
23 |
+
label=None,
|
24 |
+
lines=3
|
25 |
+
)
|
26 |
+
],
|
27 |
+
outputs=gr.HTML(),
|
28 |
+
title="Text Category Classification",
|
29 |
+
css="""
|
30 |
+
.gradio-container {
|
31 |
+
font-family: Arial, sans-serif;
|
32 |
+
}
|
33 |
+
.gradio-interface {
|
34 |
+
max-width: 800px !important;
|
35 |
+
}
|
36 |
+
#component-0 {
|
37 |
+
border-radius: 8px;
|
38 |
+
border: 1px solid #ddd;
|
39 |
+
}
|
40 |
+
.submit-button {
|
41 |
+
background-color: #ff6b33 !important;
|
42 |
+
}
|
43 |
+
.clear-button {
|
44 |
+
background-color: #f0f0f0 !important;
|
45 |
+
color: #333 !important;
|
46 |
+
}
|
47 |
+
""",
|
48 |
+
examples=[
|
49 |
+
["Messi jahon chempioni bo'ldi"],
|
50 |
+
["Yangi iPhone 15 Pro Max sotuvga chiqdi"],
|
51 |
+
["Kitob o'qish foydali"],
|
52 |
+
["Toshkentda ob-havo issiq"]
|
53 |
+
]
|
54 |
+
)
|
55 |
+
|
56 |
+
iface.launch(share=True)
|