AbrorBalxiyev commited on
Commit
7581453
·
verified ·
1 Parent(s): a2fc443

update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -1,23 +1,31 @@
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[0]}
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=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()