Spaces:
Runtime error
Runtime error
Commit
·
5262530
1
Parent(s):
4395b89
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,8 @@ import openai
|
|
2 |
import re
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Define a function to
|
6 |
-
def
|
7 |
# Set up the OpenAI API credentials
|
8 |
openai.api_key = api_key
|
9 |
|
@@ -11,31 +11,29 @@ def solve_math_problem(prompt, api_key):
|
|
11 |
response = openai.Completion.create(
|
12 |
engine="davinci",
|
13 |
prompt=prompt,
|
14 |
-
max_tokens=
|
15 |
n=1,
|
16 |
stop=None,
|
17 |
-
temperature=0.
|
18 |
)
|
19 |
|
20 |
-
# Extract the
|
21 |
answer = response.choices[0].text.strip()
|
22 |
|
23 |
-
|
24 |
-
answer = re.sub("[^0-9\.]", "", answer)
|
25 |
-
|
26 |
-
return float(answer)
|
27 |
|
28 |
# Define the Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
-
fn=
|
31 |
inputs=[
|
32 |
-
gr.inputs.Textbox(label="Enter
|
33 |
gr.inputs.Textbox(label="Enter your OpenAI API key", type="password")
|
34 |
],
|
35 |
-
outputs=gr.outputs.Textbox(label="
|
36 |
-
title="OpenAI
|
37 |
-
description="
|
38 |
-
live=True
|
|
|
39 |
)
|
40 |
|
41 |
# Launch the Gradio interface
|
|
|
2 |
import re
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Define a function to generate OpenAI responses
|
6 |
+
def generate_response(prompt, api_key):
|
7 |
# Set up the OpenAI API credentials
|
8 |
openai.api_key = api_key
|
9 |
|
|
|
11 |
response = openai.Completion.create(
|
12 |
engine="davinci",
|
13 |
prompt=prompt,
|
14 |
+
max_tokens=150,
|
15 |
n=1,
|
16 |
stop=None,
|
17 |
+
temperature=0.7,
|
18 |
)
|
19 |
|
20 |
+
# Extract the response from the API result
|
21 |
answer = response.choices[0].text.strip()
|
22 |
|
23 |
+
return answer
|
|
|
|
|
|
|
24 |
|
25 |
# Define the Gradio interface
|
26 |
iface = gr.Interface(
|
27 |
+
fn=generate_response,
|
28 |
inputs=[
|
29 |
+
gr.inputs.Textbox(label="Enter your message"),
|
30 |
gr.inputs.Textbox(label="Enter your OpenAI API key", type="password")
|
31 |
],
|
32 |
+
outputs=gr.outputs.Textbox(label="OpenAI's response"),
|
33 |
+
title="OpenAI Chatbot",
|
34 |
+
description="Ask a question or say something, and OpenAI will respond!",
|
35 |
+
live=True,
|
36 |
+
button_text="Chat"
|
37 |
)
|
38 |
|
39 |
# Launch the Gradio interface
|