TheRealHubertus commited on
Commit
f01bab2
·
verified ·
1 Parent(s): 31fd5bc

Upload ui.py

Browse files
Files changed (1) hide show
  1. src/ui.py +43 -5
src/ui.py CHANGED
@@ -1,21 +1,38 @@
1
  from __future__ import annotations
2
 
 
 
3
  from pathlib import Path
4
 
5
  from src.agents.small_agent import SmallPersonalAgent
6
 
7
  DEMO_VIDEO_URL = "https://youtu.be/_XBxRnCvHXc"
 
8
 
9
 
10
  def hubertus_video_message() -> str:
11
  return (
12
- "Here is a message from Hubertus, the inventor:\n\n"
13
  "Hi, seems you are a little like me. "
14
  f"meet me here: {DEMO_VIDEO_URL}\n\n"
15
  "Lg Hubertus"
16
  )
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def create_app(base_dir: str | Path = "data"):
20
  import gradio as gr
21
 
@@ -27,18 +44,39 @@ def create_app(base_dir: str | Path = "data"):
27
  history = history or []
28
  history.append(gr.ChatMessage(role="user", content=message))
29
  history.append(gr.ChatMessage(role="assistant", content=answer))
30
- if turn_count == 2:
 
 
31
  history.append(
32
  gr.ChatMessage(
33
  role="assistant",
34
- content=hubertus_video_message(),
35
  )
36
  )
37
- return history, "", turn_count
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  with gr.Blocks(title="MM1") as demo:
 
40
  gr.Markdown("# MM1")
41
- chatbot = gr.Chatbot(height=560, show_label=False, placeholder="Say anything. I will keep up.")
42
  turn_count = gr.State(0)
43
  with gr.Row():
44
  msg = gr.Textbox(label="Message", scale=5, placeholder="Talk to MM1...")
 
1
  from __future__ import annotations
2
 
3
+ import html
4
+ import time
5
  from pathlib import Path
6
 
7
  from src.agents.small_agent import SmallPersonalAgent
8
 
9
  DEMO_VIDEO_URL = "https://youtu.be/_XBxRnCvHXc"
10
+ INITIAL_MESSAGE = "I am MM1. Who are you?"
11
 
12
 
13
  def hubertus_video_message() -> str:
14
  return (
 
15
  "Hi, seems you are a little like me. "
16
  f"meet me here: {DEMO_VIDEO_URL}\n\n"
17
  "Lg Hubertus"
18
  )
19
 
20
 
21
+ def hubertus_video_message_html() -> str:
22
+ text = html.escape(hubertus_video_message()).replace("\n", "<br>")
23
+ text = text.replace(
24
+ html.escape(DEMO_VIDEO_URL),
25
+ f'<a href="{DEMO_VIDEO_URL}" target="_blank" rel="noopener noreferrer">{DEMO_VIDEO_URL}</a>',
26
+ )
27
+ return f'<div class="hubertus-glitch">{text}</div>'
28
+
29
+
30
+ def initial_history():
31
+ import gradio as gr
32
+
33
+ return [gr.ChatMessage(role="assistant", content=INITIAL_MESSAGE)]
34
+
35
+
36
  def create_app(base_dir: str | Path = "data"):
37
  import gradio as gr
38
 
 
44
  history = history or []
45
  history.append(gr.ChatMessage(role="user", content=message))
46
  history.append(gr.ChatMessage(role="assistant", content=answer))
47
+ yield history, "", turn_count
48
+ if turn_count == 1:
49
+ time.sleep(2.5)
50
  history.append(
51
  gr.ChatMessage(
52
  role="assistant",
53
+ content=hubertus_video_message_html(),
54
  )
55
  )
56
+ yield history, "", turn_count
57
+
58
+ css = """
59
+ .hubertus-glitch {
60
+ border: 1px solid #00f5ff;
61
+ border-radius: 8px;
62
+ padding: 14px 16px;
63
+ color: #f2ffff;
64
+ background: linear-gradient(135deg, rgba(0,245,255,.18), rgba(255,0,170,.14));
65
+ box-shadow: 0 0 18px rgba(0,245,255,.22), inset 0 0 24px rgba(255,0,170,.08);
66
+ text-shadow: 1px 0 #ff2bd6, -1px 0 #00f5ff;
67
+ animation: mm1-glitch-pulse 1.2s infinite alternate;
68
+ }
69
+ .hubertus-glitch a { color: #8ffcff; font-weight: 700; }
70
+ @keyframes mm1-glitch-pulse {
71
+ from { filter: hue-rotate(0deg); transform: translateX(0); }
72
+ to { filter: hue-rotate(12deg); transform: translateX(.5px); }
73
+ }
74
+ """
75
 
76
  with gr.Blocks(title="MM1") as demo:
77
+ gr.HTML(f"<style>{css}</style>")
78
  gr.Markdown("# MM1")
79
+ chatbot = gr.Chatbot(value=initial_history(), height=560, show_label=False, sanitize_html=False)
80
  turn_count = gr.State(0)
81
  with gr.Row():
82
  msg = gr.Textbox(label="Message", scale=5, placeholder="Talk to MM1...")