Spaces:
Runtime error
Runtime error
Jesus Carrasco
commited on
Commit
·
c3223e2
1
Parent(s):
e61b92f
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,30 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return response
|
| 9 |
|
| 10 |
-
# Create a Gradio UI for the chatbot function
|
| 11 |
iface = gr.Interface(
|
| 12 |
fn=chatbot,
|
| 13 |
-
inputs=gr.inputs.Textbox(lines=5,
|
| 14 |
-
outputs=
|
| 15 |
-
title="Chatbot
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
-
# Start the Gradio server
|
| 19 |
iface.launch()
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
+
from openai.api_resources import engines
|
| 4 |
|
| 5 |
+
openai.api_key = "your-api-key"
|
| 6 |
+
|
| 7 |
+
model_engine = "gpt-3.5-turbo"
|
| 8 |
+
|
| 9 |
+
def chatbot(prompt):
|
| 10 |
+
completions = openai.Completion.create(
|
| 11 |
+
engine=model_engine,
|
| 12 |
+
prompt=prompt,
|
| 13 |
+
max_tokens=100,
|
| 14 |
+
n=1,
|
| 15 |
+
stop=None,
|
| 16 |
+
temperature=0.5,
|
| 17 |
+
)
|
| 18 |
+
response = completions.choices[0].text.strip()
|
| 19 |
return response
|
| 20 |
|
|
|
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=chatbot,
|
| 23 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter your message here..."),
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Chatbot",
|
| 26 |
+
description="A chatbot using OpenAI's GPT-3.5-turbo",
|
| 27 |
)
|
| 28 |
|
|
|
|
| 29 |
iface.launch()
|
| 30 |
+
|