Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -11,28 +11,29 @@ model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
12 |
|
13 |
# ηζεε€ηε½ζ°
|
14 |
-
def chat(input_text,
|
15 |
-
inputs = tokenizer(input_text, return_tensors="pt").to(
|
16 |
with torch.no_grad():
|
17 |
-
outputs = model.generate(**inputs, max_length=512
|
18 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
-
|
|
|
20 |
|
21 |
# εε»Ί Gradio ηι’
|
22 |
with gr.Blocks() as demo:
|
23 |
-
gr.Markdown("
|
24 |
-
|
25 |
chatbot = gr.Chatbot(label="Chatbot")
|
26 |
-
msg = gr.Textbox(
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
# ε―ε¨ Gradio εΊη¨
|
37 |
-
if __name__ == "__main__":
|
38 |
-
demo.launch()
|
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
12 |
|
13 |
# ηζεε€ηε½ζ°
|
14 |
+
def chat(input_text, chat_history=[]):
|
15 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
16 |
with torch.no_grad():
|
17 |
+
outputs = model.generate(**inputs, max_length=512)
|
18 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
chat_history.append((input_text, response))
|
20 |
+
return chat_history, ""
|
21 |
|
22 |
# εε»Ί Gradio ηι’
|
23 |
with gr.Blocks() as demo:
|
24 |
+
gr.Markdown("# π€ Chatbot")
|
|
|
25 |
chatbot = gr.Chatbot(label="Chatbot")
|
26 |
+
msg = gr.Textbox(placeholder="Type a message...")
|
27 |
+
with gr.Row():
|
28 |
+
submit_btn = gr.Button("Submit")
|
29 |
+
retry_btn = gr.Button("π Retry")
|
30 |
+
undo_btn = gr.Button("β©οΈ Undo")
|
31 |
+
clear_btn = gr.Button("ποΈ Clear")
|
32 |
|
33 |
+
submit_btn.click(chat, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
34 |
+
retry_btn.click(chat, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
35 |
+
undo_btn.click(lambda history: history[:-1] if history else [], inputs=[chatbot], outputs=[chatbot])
|
36 |
+
clear_btn.click(lambda: [], inputs=[], outputs=[chatbot])
|
37 |
|
38 |
+
# θΏθ‘ Gradio ηι’
|
39 |
+
demo.launch()
|
|
|
|
|
|