AbrorBalxiyev
commited on
update something
Browse files
app.py
CHANGED
@@ -4,16 +4,74 @@ import gradio as gr
|
|
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 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
result += f"{item['label']}: {percentage:.1f}%\n"
|
15 |
|
16 |
-
return result
|
17 |
# Gradio interfeysi
|
18 |
iface = gr.Interface(
|
19 |
fn=classify_text,
|
|
|
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(decoded_data)
|
|
|
74 |
|
|
|
75 |
# Gradio interfeysi
|
76 |
iface = gr.Interface(
|
77 |
fn=classify_text,
|