adrien1 commited on
Commit
b58958f
1 Parent(s): 17b9008

Create .app.py

Browse files
Files changed (1) hide show
  1. .app.py +27 -0
.app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, Conversation
3
+
4
+ # Load DialoGPT-medium model and tokenizer
5
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
6
+ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
7
+
8
+ def chatbot(input_text):
9
+ # Tokenize input text
10
+ input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt")
11
+
12
+ # Generate response
13
+ response_ids = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
14
+
15
+ # Decode and return response
16
+ response_text = tokenizer.decode(response_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
17
+ return response_text
18
+
19
+ # Interface
20
+ iface = gr.Interface(
21
+ fn=chatbot,
22
+ inputs=gr.Textbox(lines=2, label="Input"),
23
+ outputs="text",
24
+ title="Chat with DialoGPT-medium"
25
+ )
26
+
27
+ iface.launch()