KaiShin1885 commited on
Commit
9cbb57b
·
verified ·
1 Parent(s): 711f8c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -1,20 +1,37 @@
1
  import gradio as gr
 
2
 
3
- def respond(val):
4
- if len(val) > 1:
5
- if val[1]:
6
- # do something
7
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  else:
9
- # handle the case where val has only one element
10
- pass
 
11
 
 
12
  demo = gr.Interface(
13
- fn=respond,
14
  inputs="text",
15
  outputs="text",
16
- title="My App",
17
- description="This is my app"
18
  )
19
 
 
20
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
 
4
+ # Load pre-trained model and tokenizer
5
+ model = AutoModelForSequenceClassification.from_pretrained("klue/bert-base-uncased")
6
+ tokenizer = AutoTokenizer.from_pretrained("klue/bert-base-uncased")
7
+
8
+ def chatbot(input_text):
9
+ # Tokenize input text
10
+ inputs = tokenizer(input_text, return_tensors="pt")
11
+
12
+ # Get model predictions
13
+ outputs = model(**inputs)
14
+ logits = outputs.logits.detach().numpy()
15
+ predicted_class = logits.argmax(-1)[0]
16
+
17
+ # Generate response based on predicted class
18
+ if predicted_class == 0:
19
+ response = "I'm happy to help you with that!"
20
+ elif predicted_class == 1:
21
+ response = "I'm not sure I understand. Can you please rephrase?"
22
  else:
23
+ response = "I'm sorry, I'm not trained to respond to that."
24
+
25
+ return response
26
 
27
+ # Create Gradio interface
28
  demo = gr.Interface(
29
+ fn=chatbot,
30
  inputs="text",
31
  outputs="text",
32
+ title="Chatbot",
33
+ description="Talk to me!"
34
  )
35
 
36
+ # Launch Gradio app
37
  demo.launch()