mariusjabami commited on
Commit
fa8b0f1
·
verified ·
1 Parent(s): 162ed73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -8
app.py CHANGED
@@ -4,8 +4,50 @@ import time
4
 
5
  client = InferenceClient("lambdaindie/lambdai")
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def respond(message, history, system_message, max_tokens, temperature, top_p):
8
- # Build base message history
9
  messages = [{"role": "system", "content": system_message}] if system_message else []
10
 
11
  for user, assistant in history:
@@ -14,7 +56,6 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
14
  if assistant:
15
  messages.append({"role": "assistant", "content": assistant})
16
 
17
- # Phase 1 — Thinking aloud (reasoning step)
18
  thinking_prompt = messages + [
19
  {
20
  "role": "user",
@@ -23,7 +64,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
23
  ]
24
 
25
  reasoning = ""
26
- yield "**Thinking...**\n```markdown\n```" # Trigger gray markdown block
27
 
28
  for chunk in client.chat_completion(
29
  thinking_prompt,
@@ -34,11 +75,11 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
34
  ):
35
  token = chunk.choices[0].delta.content or ""
36
  reasoning += token
37
- yield f"**Thinking...**\n```markdown\n{reasoning.strip()}```"
 
38
 
39
- time.sleep(0.5) # Optional dramatic pause
40
 
41
- # Phase 2 — Final answer
42
  final_prompt = messages + [
43
  {"role": "user", "content": message},
44
  {"role": "assistant", "content": reasoning.strip()},
@@ -58,9 +99,10 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
58
  yield final_answer.strip()
59
 
60
  demo = gr.ChatInterface(
61
- respond,
62
  title="LENIRΛ",
63
- theme=gr.themes.Base(primary_hue="gray", font=["JetBrains Mono", "monospace"]),
 
64
  additional_inputs=[
65
  gr.Textbox(
66
  value="You are a concise, logical AI that explains its reasoning clearly before answering.",
 
4
 
5
  client = InferenceClient("lambdaindie/lambdai")
6
 
7
+ css = """
8
+ body {
9
+ background-color: #111;
10
+ color: #e0e0e0;
11
+ font-family: 'JetBrains Mono', monospace;
12
+ }
13
+ .gr-button {
14
+ background: linear-gradient(to right, #2a2a2a, #1f1f1f);
15
+ color: white;
16
+ border-radius: 10px;
17
+ padding: 8px 16px;
18
+ font-weight: bold;
19
+ font-family: 'JetBrains Mono', monospace;
20
+ }
21
+ .gr-button:hover {
22
+ background: #333;
23
+ }
24
+ .gr-textbox textarea {
25
+ background-color: #181818 !important;
26
+ color: #fff !important;
27
+ font-family: 'JetBrains Mono', monospace;
28
+ border-radius: 8px;
29
+ }
30
+ .gr-chat-message {
31
+ font-family: 'JetBrains Mono', monospace;
32
+ }
33
+ .markdown-think {
34
+ background-color: #1e1e1e;
35
+ border-left: 4px solid #555;
36
+ padding: 10px;
37
+ margin-bottom: 8px;
38
+ font-style: italic;
39
+ white-space: pre-wrap;
40
+ font-family: 'JetBrains Mono', monospace;
41
+ animation: pulse 1.5s infinite ease-in-out;
42
+ }
43
+ @keyframes pulse {
44
+ 0% { opacity: 0.6; }
45
+ 50% { opacity: 1.0; }
46
+ 100% { opacity: 0.6; }
47
+ }
48
+ """
49
+
50
  def respond(message, history, system_message, max_tokens, temperature, top_p):
 
51
  messages = [{"role": "system", "content": system_message}] if system_message else []
52
 
53
  for user, assistant in history:
 
56
  if assistant:
57
  messages.append({"role": "assistant", "content": assistant})
58
 
 
59
  thinking_prompt = messages + [
60
  {
61
  "role": "user",
 
64
  ]
65
 
66
  reasoning = ""
67
+ yield '<div class="markdown-think">Thinking...</div>'
68
 
69
  for chunk in client.chat_completion(
70
  thinking_prompt,
 
75
  ):
76
  token = chunk.choices[0].delta.content or ""
77
  reasoning += token
78
+ styled_thought = f'<div class="markdown-think">{reasoning.strip()}</div>'
79
+ yield styled_thought
80
 
81
+ time.sleep(0.5)
82
 
 
83
  final_prompt = messages + [
84
  {"role": "user", "content": message},
85
  {"role": "assistant", "content": reasoning.strip()},
 
99
  yield final_answer.strip()
100
 
101
  demo = gr.ChatInterface(
102
+ fn=respond,
103
  title="LENIRΛ",
104
+ theme=gr.themes.Base(primary_hue="gray"),
105
+ css=css,
106
  additional_inputs=[
107
  gr.Textbox(
108
  value="You are a concise, logical AI that explains its reasoning clearly before answering.",