import gradio as gr import openai import os from dotenv import load_dotenv import pyttsx3 load_dotenv() openai.api_key = os.getenv("OPEN_API_TOKEN") messages = [{"role": "system", "content": "You are a software architect"}] def process(request): messages.append({"role": "user", "content": request}) completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages) reply = completion.choices[0].message.content engine = pyttsx3.init() engine.say(reply) engine.runAndWait() messages.append({"role": "assistant", "content": reply}) res = '' for message in messages: if message["role"] == "system": continue res += f"{message['role']}: {message['content']}\n\n" return res question_box = gr.Textbox(label="Ask question to assistant") chat_log_box = gr.Textbox(label="Chat Log", max_lines=150) ui = gr.Interface(fn=process, inputs=question_box, outputs=chat_log_box) ui.launch()