Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,10 @@ import os
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Define the conversation prompt
|
| 9 |
conversation_prompt = "Welcome to ChatRobo, kindly type in your enquiries: "
|
|
@@ -22,24 +24,18 @@ def openai_chat_history(input, history):
|
|
| 22 |
return ""
|
| 23 |
|
| 24 |
def openai_create(prompt):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
top_p=1,
|
| 36 |
-
frequency_penalty=0,
|
| 37 |
-
presence_penalty=0.6,
|
| 38 |
-
stop=["Human:", "AI:"]
|
| 39 |
-
)
|
| 40 |
-
chat_response = response.choices[0].text
|
| 41 |
|
| 42 |
-
return
|
| 43 |
|
| 44 |
block = gr.Interface(
|
| 45 |
fn=openai_chat_history,
|
|
@@ -49,4 +45,3 @@ block = gr.Interface(
|
|
| 49 |
block.launch()
|
| 50 |
|
| 51 |
|
| 52 |
-
|
|
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
| 6 |
+
|
| 7 |
+
start_sequence = "\nAI:"
|
| 8 |
+
restart_sequence = "\nHuman: "
|
| 9 |
|
| 10 |
# Define the conversation prompt
|
| 11 |
conversation_prompt = "Welcome to ChatRobo, kindly type in your enquiries: "
|
|
|
|
| 24 |
return ""
|
| 25 |
|
| 26 |
def openai_create(prompt):
|
| 27 |
+
response = openai.Completion.create(
|
| 28 |
+
model="text-davinci-003",
|
| 29 |
+
prompt=prompt,
|
| 30 |
+
temperature=0.9,
|
| 31 |
+
max_tokens=150,
|
| 32 |
+
top_p=1,
|
| 33 |
+
frequency_penalty=0,
|
| 34 |
+
presence_penalty=0.6,
|
| 35 |
+
stop=["Human:", "AI:"]
|
| 36 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
return response.choices[0].text
|
| 39 |
|
| 40 |
block = gr.Interface(
|
| 41 |
fn=openai_chat_history,
|
|
|
|
| 45 |
block.launch()
|
| 46 |
|
| 47 |
|
|
|