Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,32 +16,30 @@ def generate_response(user_input):
|
|
| 16 |
prompt = f"You said: {user_input}"
|
| 17 |
|
| 18 |
# Generate a response using the OpenAI API
|
|
|
|
| 19 |
response = openai.Completion.create(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
# Extract the response from the API output
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
break
|
| 42 |
-
response = generate_response(user_input)
|
| 43 |
-
print("Chatbot:", response)
|
| 44 |
-
print("Welcome to the chatbot!\n")
|
| 45 |
|
| 46 |
|
| 47 |
|
|
|
|
| 16 |
prompt = f"You said: {user_input}"
|
| 17 |
|
| 18 |
# Generate a response using the OpenAI API
|
| 19 |
+
def openai_create(prompt):
|
| 20 |
response = openai.Completion.create(
|
| 21 |
+
model="text-davinci-003",
|
| 22 |
+
prompt=prompt,
|
| 23 |
+
temperature=0.9,
|
| 24 |
+
max_tokens=150,
|
| 25 |
+
top_p=1,
|
| 26 |
+
frequency_penalty=0,
|
| 27 |
+
presence_penalty=0.6,
|
| 28 |
+
stop=["Human:", "AI:"]
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
|
| 32 |
# Extract the response from the API output
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
return response.choices[0].text
|
| 36 |
+
|
| 37 |
+
block = gr.Interface(
|
| 38 |
+
fn=openai_chat_history,
|
| 39 |
+
inputs=[gr.inputs.Textbox(placeholder=conversation_prompt)],
|
| 40 |
+
outputs=[gr.outputs.Textbox(label="ChatRobo Output")]
|
| 41 |
+
)
|
| 42 |
+
block.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
|