import gradio as gr def create_ui(generate_fn): """ Build a Blocks-based chat UI that returns a gr.Blocks object. generate_fn receives a list of messages (user/assistant pairs as dicts) and should return a reply string (this wrapper uses it as a placeholder). """ with gr.Blocks(css=""" body { background-color: #0b0f19; color: #e0e0e0; } .gradio-container { font-family: 'Inter', sans-serif; max-width: 900px !important; margin: auto; } footer { visibility: hidden; display: none; } """) as demo: gr.Markdown("## Nexari AI — Research Backend") chatbot = gr.Chatbot(elem_id="nexari_chatbot", label="Nexari").style(height=500) txt = gr.Textbox(show_label=False, placeholder="Type your message and press Enter") state = gr.State([]) def submit(message, history): # history is list of (human, ai) pairs in Gradio; convert to messages messages = [] for human, ai in history: messages.append({"role": "user", "content": human}) messages.append({"role": "assistant", "content": ai}) messages.append({"role": "user", "content": message}) # call generator wrapper (synchronous placeholder) reply = generate_fn(messages) # append to history history = history + [(message, reply)] return history, "" txt.submit(submit, [txt, state], [chatbot, txt], queue=False) # Also allow clicking a send button send = gr.Button("Send") send.click(submit, [txt, state], [chatbot, txt], queue=False) return demo