Create Test 1.0
Browse files
Test 1.0
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# 使用公开的模型进行测试
|
5 |
+
model_name = "gpt2"
|
6 |
+
pipe = pipeline("text-generation", model=model_name, tokenizer=model_name)
|
7 |
+
|
8 |
+
def chat_with_ai(prompt):
|
9 |
+
response = pipe(prompt, max_length=100, do_sample=True)
|
10 |
+
return response[0]["generated_text"]
|
11 |
+
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
gr.Markdown("# 🤖 AI Chatbot")
|
14 |
+
chatbot = gr.Chatbot()
|
15 |
+
msg = gr.Textbox(label="Type your message:")
|
16 |
+
clear = gr.Button("Clear")
|
17 |
+
|
18 |
+
def respond(message, chat_history):
|
19 |
+
response = chat_with_ai(message)
|
20 |
+
chat_history.append((message, response))
|
21 |
+
return "", chat_history
|
22 |
+
|
23 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
24 |
+
clear.click(lambda: [], None, chatbot)
|
25 |
+
|
26 |
+
demo.launch()
|