Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,37 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
else:
|
9 |
-
|
10 |
-
|
|
|
11 |
|
|
|
12 |
demo = gr.Interface(
|
13 |
-
fn=
|
14 |
inputs="text",
|
15 |
outputs="text",
|
16 |
-
title="
|
17 |
-
description="
|
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()
|