Spaces:
Running
Running
Update app.py
Browse filesadd chatgpt api
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|