SYNTHIA / app.py
Ari-ch's picture
Add app.py with SYNTHIA chatbot code β€” first version
c72493f verified
raw
history blame
1.13 kB
import os
import openai
import gradio as gr
openai.api_key = os.getenv("OPENAI_API_KEY")
def chat_with_synthia(user_message, chat_history):
messages = [{"role": "system", "content": "You are SYNTHIA, a helpful and friendly AI assistant."}]
for user, bot in chat_history:
messages.append({"role": "user", "content": user})
messages.append({"role": "assistant", "content": bot})
messages.append({"role": "user", "content": user_message})
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=messages,
max_tokens=150,
temperature=0.7,
)
reply = response.choices[0].message['content']
chat_history.append((user_message, reply))
return "", chat_history
with gr.Blocks() as app:
gr.Markdown("# SYNTHIA β€” Your smart AI assistant πŸ€–πŸ’–")
chatbot = gr.Chatbot()
msg = gr.Textbox(placeholder="Say something to SYNTHIA...")
clear = gr.Button("Clear")
msg.submit(chat_with_synthia, [msg, chatbot], [msg, chatbot])
clear.click(lambda: None, None, chatbot, queue=False)
if __name__ == "__main__":
app.launch()