Samuelblue commited on
Commit
54bc020
·
1 Parent(s): a7247a1
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -2,16 +2,32 @@
2
 
3
  import gradio as gr
4
 
5
- from transformers import AutoModelWithLMHead, AutoTokenizer
 
6
 
7
- tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
8
- model = AutoModelWithLMHead.from_pretrained("microsoft/DialoGPT-medium")
9
 
10
- def chatbot(input_text):
11
- input_ids = tokenizer.encode(input_text, return_tensors='pt')
12
- output = model.generate(input_ids, max_length=50, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=3)
13
- output_text = tokenizer.decode(output[0], skip_special_tokens=True)
14
- return output_text
15
 
16
- iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", description="ChatGPT")
17
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import gradio as gr
4
 
5
+ # Create a text input
6
+ text_input = gr.inputs.Textbox(lines=2, label="Enter your text:")
7
 
8
+ # Create a ChatGPT object
9
+ chatgpt = gr.ChatGPT()
10
 
11
+ # Create a text output
12
+ text_output = gr.outputs.Textbox(label="ChatGPT Output:")
 
 
 
13
 
14
+ # Create a button
15
+ button = gr.inputs.Button(label="Submit")
16
+
17
+ # Create a form
18
+ form = gr.Interface(
19
+ text_input,
20
+ button,
21
+ text_output,
22
+ title="ChatGPT",
23
+ description="Chat with a GPT-3 model"
24
+ )
25
+
26
+ # Define the function that will be called when the button is clicked
27
+ def process_input(values):
28
+ text = values["text_input"]
29
+ response = chatgpt.chat(text)
30
+ return {"text_output": response}
31
+
32
+ # Launch the form
33
+ form.launch(process_input)