daniloedu commited on
Commit
c36c5f2
·
verified ·
1 Parent(s): 8ba25d5

create app.py

Browse files

First version of the chat interface.

Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the pre-trained LLM model and tokenizer
5
+ model_name = "microsoft/DialoGPT-medium"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Define the function to generate the chatbot response
10
+ def chatbot(input_text):
11
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
12
+ output = model.generate(input_ids, max_length=1000, do_sample=True, top_p=0.92, top_k=0, num_return_sequences=1)
13
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
14
+ return response
15
+
16
+ # Create the Gradio interface
17
+ chat_interface = gr.Blocks()
18
+
19
+ with chat_interface:
20
+ gr.Markdown("# Chatbot")
21
+ chatbot_input = gr.Textbox(placeholder="Type your message here...")
22
+ chatbot_output = gr.Textbox(label="Chatbot Response")
23
+ chat_btn = gr.Button("Send")
24
+ chat_btn.click(chatbot, inputs=chatbot_input, outputs=chatbot_output)
25
+
26
+ chat_interface.launch()