mrsandip commited on
Commit
71a8fc3
·
verified ·
1 Parent(s): 585ddcb

Enhance chat window UI

Browse files
Files changed (1) hide show
  1. app/ui.py +61 -28
app/ui.py CHANGED
@@ -1,37 +1,70 @@
1
- """Coding AI mode UI: reasoning (live->collapsed) + image + file + video."""
2
- import time, gradio as gr
3
  from pathlib import Path
 
4
 
5
- def mock_reason(prompt, image, file, video):
6
- steps = []
 
 
 
 
 
7
  ctx = []
8
- if image: ctx.append(f"image: {Path(image).name}")
9
- if file: ctx.append(f"file: {Path(file).name if isinstance(file,str) else 'uploaded'}")
10
- if video: ctx.append(f"video: {Path(video).name} (4 frames extracted)")
11
- header = f"Context: {', '.join(ctx)}\n" if ctx else ""
12
- yield "[Thinking...]", f"{header}Understanding: {prompt[:120]}..."
13
- time.sleep(0.4)
14
- yield "[Planning...]", f"{header}Plan: 1.parse 2.generate 3.verify"
15
- time.sleep(0.4)
16
- code = f"```python\n# generated for: {prompt[:60]}\ndef solve():\n return 'todo: wire to outputs/tiny-50M.gguf'\n```"
17
- yield "[Coding...]", f"{header}{code}"
18
- time.sleep(0.3)
19
- yield "[Done]", f"{header}<details><summary>Reasoning (3 steps)</summary>Understand > Plan > Code</details>\n\n{code}"
 
 
 
 
 
20
 
21
- with gr.Blocks(title="Alfa-Code") as demo:
22
- gr.Markdown("# Alfa-Code: reasoning + image + file + video")
 
 
 
 
 
 
 
 
 
 
23
  with gr.Row():
24
- with gr.Column(scale=2):
25
- chat = gr.Markdown()
26
- prompt = gr.Textbox(label="Prompt", placeholder="Describe code task...")
 
 
 
 
 
 
 
27
  with gr.Row():
28
- img = gr.Image(label="Image", type="filepath")
29
- fil = gr.File(label="File")
30
- vid = gr.Video(label="Video")
31
- btn = gr.Button("Generate", variant="primary")
32
  with gr.Column(scale=1):
33
- status = gr.Label(value="Idle", label="Reasoning status")
34
- btn.click(fn=mock_reason, inputs=[prompt, img, fil, vid], outputs=[status, chat])
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
- demo.launch(server_name="127.0.0.1", server_port=7860)
 
 
 
1
+ """Alfa-Code chat window: ChatGPT-like + reasoning + image/file/video."""
2
+ import time
3
  from pathlib import Path
4
+ import gradio as gr
5
 
6
+ CSS = """
7
+ #chatbot {height: 55vh !important;}
8
+ .message {font-size: 15px;}
9
+ #send {background: #ff6a00 !important; color: white !important;}
10
+ """
11
+
12
+ def stream_reply(message, history, image, file, video):
13
  ctx = []
14
+ if image: ctx.append(f"🖼️ {Path(image).name}")
15
+ if file:
16
+ fp = file if isinstance(file, str) else getattr(file, "name", "file")
17
+ ctx.append(f"📄 {Path(fp).name}")
18
+ if video: ctx.append(f"🎬 {Path(video).name} (frames extracted)")
19
+ prefix = (" ".join(ctx) + "\n\n" if ctx else "")
20
+
21
+ history = history + [
22
+ {"role": "user", "content": prefix + (message or "(attachment only)")},
23
+ {"role": "assistant", "content": "⏳ *Thinking...*"},
24
+ ]
25
+ yield history, "⏳ Thinking..."
26
+ time.sleep(0.5)
27
+
28
+ history[-1]["content"] = "🧠 *Planning...*\n- parse request\n- check attachments\n- generate code"
29
+ yield history, "🧠 Planning..."
30
+ time.sleep(0.5)
31
 
32
+ code = f"```python\n# task: {(message or 'multimodal')[:80]}\ndef solve():\n # TODO: wire outputs/tiny-50M.gguf\n return 'done'\n```"
33
+ final = (
34
+ "<details open><summary><b>Reasoning (3 steps)</b></summary>\n"
35
+ "1. Understand request + attachments<br>2. Plan: parse → generate → verify<br>"
36
+ "3. Code + self-check</details>\n\n" + prefix + code
37
+ )
38
+ history[-1]["content"] = final
39
+ yield history, "✅ Done"
40
+ return history, "✅ Done"
41
+
42
+ with gr.Blocks(title="Alfa-Code", css=CSS, theme=gr.themes.Soft()) as demo:
43
+ gr.Markdown("# 💬 Alfa-Code\n*Coding AI — reasoning + image + file + video*")
44
  with gr.Row():
45
+ with gr.Column(scale=3):
46
+ chatbot = gr.Chatbot(label="Chat", elem_id="chatbot", type="messages", show_copy_button=True)
47
+ with gr.Row():
48
+ msg = gr.Textbox(placeholder="Ask to code... (Enter to send)", show_label=False, scale=4)
49
+ send = gr.Button("Send ➤", elem_id="send", scale=1)
50
+ with gr.Accordion("📎 Attachments", open=True):
51
+ with gr.Row():
52
+ img = gr.Image(label="Image", type="filepath")
53
+ fil = gr.File(label="File")
54
+ vid = gr.Video(label="Video")
55
  with gr.Row():
56
+ clear = gr.ClearButton([msg, chatbot])
57
+ retry = gr.Button("↻ Retry")
 
 
58
  with gr.Column(scale=1):
59
+ status = gr.Label(value="Idle", label="Reasoning")
60
+ gr.Examples(
61
+ ["Write python quicksort", "Fix this CSS flex bug", "Explain this traceback"],
62
+ inputs=msg, label="Try",
63
+ )
64
+ msg.submit(stream_reply, [msg, chatbot, img, fil, vid], [chatbot, status]).then(lambda: "", None, msg)
65
+ send.click(stream_reply, [msg, chatbot, img, fil, vid], [chatbot, status]).then(lambda: "", None, msg)
66
 
67
  if __name__ == "__main__":
68
+ import sys
69
+ port = int(sys.argv[1]) if len(sys.argv) > 1 else 7861
70
+ demo.launch(server_name="127.0.0.1", server_port=port)