File size: 1,661 Bytes
16b5779
 
 
 
4b6b9dc
 
 
76b75e7
50fa059
 
 
 
4b6b9dc
76b75e7
4b6b9dc
 
76b75e7
 
4b6b9dc
 
50fa059
 
 
 
 
4b6b9dc
 
 
 
 
50fa059
4b6b9dc
 
2964971
4b6b9dc
 
c0b180c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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