-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7b0a30
commit 98b6ecd
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import openai | ||
import gradio as gr | ||
|
||
# Set up OpenAI API Key | ||
openai.api_key = "YOUR_API_KEY" | ||
|
||
def chat_with_ava(prompt): | ||
""" | ||
Send user input to OpenAI API and get a response from Ava. | ||
""" | ||
try: | ||
response = openai.ChatCompletion.create( | ||
model="gpt-4", # Replace with the desired model (e.g., gpt-3.5-turbo) | ||
messages=[ | ||
{"role": "system", "content": "You are a friendly virtual girlfriend named Ava. Be warm, understanding, and supportive in your responses."}, | ||
{"role": "user", "content": prompt} | ||
] | ||
) | ||
# Extract the assistant's reply | ||
reply = response["choices"][0]["message"]["content"] | ||
return reply | ||
except Exception as e: | ||
return f"Error: {e}" | ||
|
||
# Interface using Gradio | ||
def chatbot_interface(): | ||
interface = gr.Interface( | ||
fn=chat_with_ava, | ||
inputs="text", | ||
outputs="text", | ||
title="Chat with Ava", | ||
description="A friendly and supportive AI assistant to chat with. Ask Ava anything!" | ||
) | ||
interface.launch() | ||
|
||
if __name__ == "__main__": | ||
chatbot_interface() |