File size: 1,360 Bytes
1e25ffc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
import gradio as gr

CSS = """
.gradio-container { background: #ffe9f3 !important; }
h2 { color: #37324a !important; }
"""

with gr.Blocks(title="smoke test", css=CSS) as demo:
    gr.Markdown(
        "## smoke test\n"
        "If you can read this and the background is **pink**, the UI loaded.\n"
        "Type something and hit send. If you get an echo, it works."
    )

    chat = gr.Chatbot(type="messages", height=300, show_label=False, elem_id="smoke-chat")

    tray = gr.MultimodalTextbox(
        file_types=["image"],
        placeholder="say hi",
        show_label=False,
        submit_btn="send",
    )

    def respond(value, history):
        history = list(history or [])

        text = ""
        files = []
        if isinstance(value, dict):
            text = (value.get("text") or "").strip()
            files = value.get("files") or []
        else:
            text = str(value or "").strip()

        if not text and not files:
            return history, None

        shown = text if text else "(no text)"
        if files:
            shown += f"  [+{len(files)} file(s)]"

        history.append({"role": "user", "content": shown})
        history.append({"role": "assistant", "content": f"echo: {shown}"})
        return history, None

    tray.submit(respond, [tray, chat], [chat, tray])

demo.queue().launch(ssr_mode=False)