Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,46 +2,41 @@ import os
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def openai_chat_history(input, history):
|
| 15 |
-
history = history or []
|
| 16 |
-
if input.strip() != "":
|
| 17 |
-
s = list(sum(history, ()))
|
| 18 |
-
s.append(input)
|
| 19 |
-
inp = ' '.join(s)
|
| 20 |
-
output = openai_create(inp)
|
| 21 |
-
history.append((input, output))
|
| 22 |
-
return history[-1][1]
|
| 23 |
else:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
|
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Set up OpenAI API credentials
|
| 6 |
+
openai.api_key = "YOUR_API_KEY"
|
| 7 |
+
|
| 8 |
+
# Define a function to generate a response to user input
|
| 9 |
+
def generate_response(user_input):
|
| 10 |
+
# Check if user input contains the phrase "who created you"
|
| 11 |
+
if "who created you" in user_input.lower():
|
| 12 |
+
# Generate a response that includes your name
|
| 13 |
+
chat_response = f"I was created by {ramv}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
else:
|
| 15 |
+
# Construct the prompt with the user input
|
| 16 |
+
prompt = f"You said: {user_input}"
|
| 17 |
+
|
| 18 |
+
# Generate a response using the OpenAI API
|
| 19 |
+
response = openai.Completion.create(
|
| 20 |
+
engine="text-davinci-002",
|
| 21 |
+
prompt=prompt,
|
| 22 |
+
temperature=0.7,
|
| 23 |
+
max_tokens=1024,
|
| 24 |
+
n=1,
|
| 25 |
+
stop=None,
|
| 26 |
+
frequency_penalty=0,
|
| 27 |
+
presence_penalty=0
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Extract the response from the API output
|
| 31 |
+
chat_response = response.choices[0].text.strip()
|
| 32 |
+
|
| 33 |
+
return chat_response
|
| 34 |
+
|
| 35 |
+
# Test the chatbot
|
| 36 |
+
while True:
|
| 37 |
+
user_input = input("You: ")
|
| 38 |
+
response = generate_response(user_input)
|
| 39 |
+
print("Chatbot:", response)
|
| 40 |
+
|
| 41 |
|
| 42 |
|