Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
-
from openai import
|
| 3 |
-
client = OpenAI()
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
|
| 7 |
# Set up OpenAI API credentials
|
| 8 |
api_key = os.environ.get("OPENAI_API_KEY")
|
| 9 |
-
|
| 10 |
|
| 11 |
# Define a function to generate a response to user input
|
| 12 |
def generate_response(user_input):
|
| 13 |
if "who created you" in user_input.lower():
|
| 14 |
chat_response = "I was created by Ram.V"
|
| 15 |
elif "who is superstar" in user_input.lower():
|
| 16 |
-
chat_response =
|
| 17 |
-
|
| 18 |
-
chat_response = "Jailer Movie releasing! Alappara Kelappurom Thalaivaru Nerandharam!"
|
| 19 |
-
elif "what is the weather like" in user_input.lower():
|
| 20 |
-
chat_response = "I'm sorry, but I don't have the ability to check the weather. Is there something else I can help you with?"
|
| 21 |
-
elif "how are you" in user_input.lower():
|
| 22 |
-
chat_response = "I'm a chatbot created by Ram.V. I don't have feelings, but thanks for asking. Hope you're well! :-)"
|
| 23 |
-
elif "what's your name" in user_input.lower():
|
| 24 |
-
chat_response = "My name is ChatRobo :-)"
|
| 25 |
else:
|
| 26 |
-
prompt = f"You said: {user_input}"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
# Generate a response using the OpenAI API
|
| 30 |
-
from openai import OpenAI
|
| 31 |
-
client = OpenAI()
|
| 32 |
-
|
| 33 |
response = client.chat.completions.create(
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Extract the response from the API output
|
| 44 |
-
chat_response = response.choices[0].text.strip()
|
| 45 |
|
| 46 |
return chat_response
|
| 47 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
from openai import Client
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
# Set up OpenAI API credentials
|
| 6 |
api_key = os.environ.get("OPENAI_API_KEY")
|
| 7 |
+
client = Client(api_key)
|
| 8 |
|
| 9 |
# Define a function to generate a response to user input
|
| 10 |
def generate_response(user_input):
|
| 11 |
if "who created you" in user_input.lower():
|
| 12 |
chat_response = "I was created by Ram.V"
|
| 13 |
elif "who is superstar" in user_input.lower():
|
| 14 |
+
chat_response = "The one and only * Superstar Rajinikanth * Thalaiva!"
|
| 15 |
+
# Add other predefined responses here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
else:
|
|
|
|
|
|
|
|
|
|
| 17 |
# Generate a response using the OpenAI API
|
|
|
|
|
|
|
|
|
|
| 18 |
response = client.chat.completions.create(
|
| 19 |
+
model="gpt-3.5-turbo-1106",
|
| 20 |
+
response_format={"type": "json_object"},
|
| 21 |
+
messages=[
|
| 22 |
+
{"role": "system", "content": "You are a helpful assistant designed to output JSON."},
|
| 23 |
+
{"role": "user", "content": user_input}
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
chat_response = response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
return chat_response
|
| 29 |
|