Update app.py
#2
by
fanaf91318
- opened
app.py
CHANGED
@@ -4,113 +4,113 @@ import gradio as gr
|
|
4 |
# Pipeline
|
5 |
pipe = pipeline("text-classification", model="AbrorBalxiyev/my_awesome_model", return_all_scores=True)
|
6 |
|
7 |
-
|
8 |
-
#
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
#
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
demo=gr.Interface.from_pipeline(pipe)
|
116 |
-
demo.launch(debug=True)
|
|
|
4 |
# Pipeline
|
5 |
pipe = pipeline("text-classification", model="AbrorBalxiyev/my_awesome_model", return_all_scores=True)
|
6 |
|
7 |
+
def get_html_for_results(results):
|
8 |
+
# Sort results by score in descending order
|
9 |
+
sorted_results = sorted(results, key=lambda x: x['score'], reverse=True)
|
10 |
|
11 |
+
html = """
|
12 |
+
<style>
|
13 |
+
.result-container {
|
14 |
+
font-family: Arial, sans-serif;
|
15 |
+
max-width: 600px;
|
16 |
+
margin: 20px auto;
|
17 |
+
}
|
18 |
+
.category-row {
|
19 |
+
margin: 10px 0;
|
20 |
+
}
|
21 |
+
.category-name {
|
22 |
+
display: inline-block;
|
23 |
+
width: 120px;
|
24 |
+
font-size: 14px;
|
25 |
+
color: #333;
|
26 |
+
}
|
27 |
+
.progress-bar {
|
28 |
+
display: inline-block;
|
29 |
+
width: calc(100% - 200px);
|
30 |
+
height: 20px;
|
31 |
+
background-color: #f0f0f0;
|
32 |
+
border-radius: 10px;
|
33 |
+
overflow: hidden;
|
34 |
+
margin-right: 10px;
|
35 |
+
}
|
36 |
+
.progress {
|
37 |
+
height: 100%;
|
38 |
+
background-color: #ff6b33;
|
39 |
+
border-radius: 10px;
|
40 |
+
transition: width 0.5s ease-in-out;
|
41 |
+
}
|
42 |
+
.percentage {
|
43 |
+
display: inline-block;
|
44 |
+
width: 50px;
|
45 |
+
text-align: right;
|
46 |
+
color: #666;
|
47 |
+
}
|
48 |
+
</style>
|
49 |
+
<div class="result-container">
|
50 |
+
"""
|
51 |
|
52 |
+
for item in sorted_results:
|
53 |
+
percentage = item['score'] * 100
|
54 |
+
html += f"""
|
55 |
+
<div class="category-row">
|
56 |
+
<span class="category-name">{item['label']}</span>
|
57 |
+
<div class="progress-bar">
|
58 |
+
<div class="progress" style="width: {percentage}%;"></div>
|
59 |
+
</div>
|
60 |
+
<span class="percentage">{percentage:.0f}%</span>
|
61 |
+
</div>
|
62 |
+
"""
|
63 |
|
64 |
+
html += "</div>"
|
65 |
+
return html
|
66 |
|
67 |
+
# Gradio interfeysi uchun funksiyani qayta yozish
|
68 |
+
def classify_text(text):
|
69 |
+
if not text.strip():
|
70 |
+
return "Please enter some text to classify."
|
71 |
|
72 |
+
pred = pipe(text)
|
73 |
+
return get_html_for_results(pred[0])
|
74 |
|
75 |
+
# Gradio interfeysi
|
76 |
+
iface = gr.Interface(
|
77 |
+
fn=classify_text,
|
78 |
+
inputs=[
|
79 |
+
gr.Textbox(
|
80 |
+
placeholder="Enter text to classify...",
|
81 |
+
label=None,
|
82 |
+
lines=3
|
83 |
+
)
|
84 |
+
],
|
85 |
+
outputs=gr.HTML(),
|
86 |
+
title="Text Category Classification",
|
87 |
+
css="""
|
88 |
+
.gradio-container {
|
89 |
+
font-family: Arial, sans-serif;
|
90 |
+
}
|
91 |
+
.gradio-interface {
|
92 |
+
max-width: 800px !important;
|
93 |
+
}
|
94 |
+
#component-0 {
|
95 |
+
border-radius: 8px;
|
96 |
+
border: 1px solid #ddd;
|
97 |
+
}
|
98 |
+
.submit-button {
|
99 |
+
background-color: #ff6b33 !important;
|
100 |
+
}
|
101 |
+
.clear-button {
|
102 |
+
background-color: #f0f0f0 !important;
|
103 |
+
color: #333 !important;
|
104 |
+
}
|
105 |
+
""",
|
106 |
+
examples=[
|
107 |
+
["Messi jahon chempioni bo'ldi"],
|
108 |
+
["Yangi iPhone 15 Pro Max sotuvga chiqdi"],
|
109 |
+
["Kitob o'qish foydali"],
|
110 |
+
["Toshkentda ob-havo issiq"]
|
111 |
+
]
|
112 |
+
)
|
113 |
|
114 |
+
iface.launch(share=True)
|
115 |
+
# demo=gr.Interface.from_pipeline(pipe)
|
116 |
+
# demo.launch(debug=True)
|