humy65 commited on
Commit
2a29ecf
verified
1 Parent(s): c114ec8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -1,17 +1,33 @@
1
  import gradio as gr
 
 
2
 
3
- # Define your function
4
- def greet(name):
5
- return f"Hello, {name}! 馃憢"
 
6
 
7
- # Create the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  demo = gr.Interface(
9
- fn=greet,
10
- inputs=gr.Textbox(label="Enter your Name:"),
11
- outputs=gr.Textbox(label="Greeting"),
12
- title="Simple Greeting App",
13
- description="Type your name and get a friendly hello!"
 
14
  )
15
 
16
- # Launch the app
17
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
 
5
+ # Load model and tokenizer from Hugging Face Hub
6
+ model_name = "YOUR_USERNAME/hebrew-intent-classifier"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
 
10
+ # Define intent labels (adjust to match your model's output)
11
+ intent_labels = ["砖讻讞转 住讬住诪讛", "讘讬讟讜诇 诪谞讜讬", "砖讗诇讛 讻诇诇讬转", "转诪讬讻讛 讟讻谞讬转"]
12
+
13
+ def classify_intent(text):
14
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
15
+ with torch.no_grad():
16
+ outputs = model(**inputs)
17
+ probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
18
+ top_prob, top_label = torch.max(probs, dim=1)
19
+ intent = intent_labels[top_label.item()]
20
+ confidence = top_prob.item()
21
+ return f"讻讜讜谞讛: {intent}\n专诪转 讘讬讟讞讜谉: {confidence:.2f}"
22
+
23
+ # Build Gradio interface
24
  demo = gr.Interface(
25
+ fn=classify_intent,
26
+ inputs=gr.Textbox(label="讛拽诇讚 砖讗诇讛 讘注讘专讬转", placeholder="诇讚讜讙诪讛: 砖讻讞转讬 讗转 讛住讬住诪讛 砖诇讬"),
27
+ outputs=gr.Textbox(label="转讜爪讗讛"),
28
+ title="馃攳 诪住讜讜讙 讻讜讜谞讜转 讘注讘专讬转",
29
+ description="诪讜讚诇 诇讝讬讛讜讬 讻讜讜谞讜转 讘砖驻讛 讛注讘专讬转. 讛拽诇讚 砖讗诇讛 讜专讗讛 讗转 讛讻讜讜谞讛 讛诪砖讜注专转.",
30
+ theme="soft"
31
  )
32
 
 
33
  demo.launch()