import gradio as gr import logging import requests import yaml logging.basicConfig( format="%(asctime)s | %(levelname)s | %(funcName)s : %(message)s", datefmt="%Y-%m-%d %H:%M:%S", level=logging.INFO, ) with open("config.yml", "r") as file: config = yaml.safe_load(file) BASE_URL = config["server"]["url"] def chat(message, history): messages = [] for (user_msg, bot_msg) in history: messages.append({"role": "user", "content": user_msg}) messages.append({"role": "system", "content": bot_msg}) logging.info(f"Sending chat message to backend ('{message}').") response = requests.post(BASE_URL + "/ask", json={"question": message, "person": "Pierre", "history": messages}) if response.status_code == 200: logging.info("Response:") logging.info(response.json()) data = response.json() return data["answer"] else: logging.error(response) ui = gr.ChatInterface(chat, title="Chat") if __name__ == "__main__": logging.info("Launching frontend.") ui.launch( #share=False, server_name='0.0.0.0', )