Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
def chat_with_gpt(input_text):
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Gradio user interface
|
11 |
input_text = gr.inputs.Textbox(lines=5, label="Your question about AI:")
|
12 |
output_text = gr.outputs.Textbox(label="ChatGPT Response:")
|
13 |
|
14 |
-
iface = gr.Interface(fn=chat_with_gpt
|
15 |
-
iface.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
import openai
|
4 |
+
|
5 |
+
# Set up OpenAI API
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
def chat_with_gpt(input_text):
|
9 |
+
model_engine = "text-davinci-002" # Choose the appropriate model engine.
|
10 |
+
prompt = f"{input_text} (AI):"
|
11 |
+
|
12 |
+
response = openai.Completion.create(
|
13 |
+
engine=model_engine,
|
14 |
+
prompt=prompt,
|
15 |
+
max_tokens=100,
|
16 |
+
n=1,
|
17 |
+
stop=None,
|
18 |
+
temperature=0.8,
|
19 |
+
top_p=1,
|
20 |
+
frequency_penalty=0,
|
21 |
+
presence_penalty=0
|
22 |
+
)
|
23 |
+
|
24 |
+
generated_text = response.choices[0].text.strip()
|
25 |
+
return generated_text
|
26 |
|
27 |
# Gradio user interface
|
28 |
input_text = gr.inputs.Textbox(lines=5, label="Your question about AI:")
|
29 |
output_text = gr.outputs.Textbox(label="ChatGPT Response:")
|
30 |
|
31 |
+
iface = gr.Interface(fn=chat_with_gpt)
|
|