import gradio as gr from g4f.client import Client client = Client() def get_response(message, history): formatted_history = [] for user, assistant in history: formatted_history.append({"role": "user", "content": user}) formatted_history.append({"role": "assistant", "content": assistant}) formatted_history.append({"role": "user", "content": message}) response = client.chat.completions.create( model="gpt-4o", messages=formatted_history, temperature=0.5 ) return response.choices[0].message.content gr.ChatInterface( get_response, chatbot=gr.Chatbot(height=300), textbox=gr.Textbox(placeholder="You can ask anything", container=False, scale=7), title="OpenAI GPT-4o", retry_btn=None, undo_btn="Delete Previous", clear_btn="Clear" ).launch() gr.ChatInterface(get_response).launch()