AbrorBalxiyev commited on
Commit
cb86f7e
·
verified ·
1 Parent(s): 7938776

update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -23
app.py CHANGED
@@ -1,23 +1,56 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- # Pipeline-ni o'rnatish
5
- pipe = pipeline("text-classification", model="AbrorBalxiyev/my_awesome_model")
6
-
7
- # Klassifikatsiya funksiyasi
8
- def classify_text(text):
9
- results = pipe(text)
10
- output = {result['label']: f"{result['score'] * 100:.2f}%" for result in results}
11
- return output
12
-
13
- # Gradio interfeysini yaratish
14
- with gr.Blocks() as demo:
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
- classify_button.click(classify_text, inputs=text_input, outputs=output_label)
21
-
22
- # Interfeysni ishga tushirish
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=[
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)