Jack7510 commited on
Commit
1756b81
1 Parent(s): d0bcccd

Update app.py

Browse files

add chatgpt api

Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -1,7 +1,27 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ import openai
3
+ import os
4
 
5
+ # Set up the OpenAI API credentials
6
+ openai.api_key = os.environ["OPENAI_API_KEY"]
7
 
8
+ # Define the chatbot function
9
+ def chatbot(text):
10
+ # Call the OpenAI API to generate a response
11
+ response = openai.Completion.create(
12
+ engine="davinci",
13
+ prompt=text,
14
+ max_tokens=1024,
15
+ n=1,
16
+ stop=None,
17
+ temperature=0.5,
18
+ )
19
+
20
+ # Extract the generated response and return it
21
+ return response.choices[0].text.strip()
22
+
23
+ # Create the Gradio interface
24
+ iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-3 Chatbot")
25
+
26
+ # Launch the interface
27
  iface.launch()