Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,65 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
# Inicia o cliente para o modelo
|
5 |
client = InferenceClient("lambdaindie/lambdai")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
}
|
17 |
-
button.pulse {
|
18 |
-
background-color: #272727 !important;
|
19 |
-
border: 1px solid #444 !important;
|
20 |
-
color: #e0e0e0 !important;
|
21 |
-
border-radius: 10px;
|
22 |
-
animation: pulse 2s infinite;
|
23 |
-
}
|
24 |
-
@keyframes pulse {
|
25 |
-
0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.5); }
|
26 |
-
70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255,255,255,0); }
|
27 |
-
100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0); }
|
28 |
}
|
29 |
.loader {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
}
|
37 |
@keyframes spin {
|
38 |
-
|
39 |
-
100% { transform: rotate(360deg); }
|
40 |
}
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
margin-bottom: 8px;
|
46 |
-
font-style: italic;
|
47 |
-
color: #aaaaaa;
|
48 |
-
display: flex;
|
49 |
-
align-items: center;
|
50 |
}
|
51 |
"""
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
f"</div>"
|
60 |
)
|
61 |
-
yield
|
62 |
-
|
63 |
-
response = client.chat_completion([{"role": "user", "content": message}], stream=False)
|
64 |
-
answer = response['choices'][0]['message']['content']
|
65 |
-
yield chat_history + [{"role": "user", "content": message}, {"role": "assistant", "content": answer}]
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
chatbot = gr.Chatbot(elem_id="chatbot", height=480, render_markdown=True)
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
client = InferenceClient("lambdaindie/lambdai")
|
5 |
|
6 |
+
css = """
|
7 |
+
.thinking-html {
|
8 |
+
display: flex;
|
9 |
+
align-items: center;
|
10 |
+
gap: 8px;
|
11 |
+
color: #666;
|
12 |
+
font-style: italic;
|
13 |
+
margin-bottom: 5px;
|
14 |
+
animation: pulse 1.5s infinite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
.loader {
|
17 |
+
width: 14px;
|
18 |
+
height: 14px;
|
19 |
+
border: 2px solid #ccc;
|
20 |
+
border-top: 2px solid #666;
|
21 |
+
border-radius: 50%;
|
22 |
+
animation: spin 1s linear infinite;
|
23 |
}
|
24 |
@keyframes spin {
|
25 |
+
to { transform: rotate(360deg); }
|
|
|
26 |
}
|
27 |
+
@keyframes pulse {
|
28 |
+
0% { opacity: 1; transform: scale(1); }
|
29 |
+
50% { opacity: 0.6; transform: scale(1.05); }
|
30 |
+
100% { opacity: 1; transform: scale(1); }
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
"""
|
33 |
|
34 |
+
def respond(message, history):
|
35 |
+
thinking = (
|
36 |
+
"<div class='thinking-html'>"
|
37 |
+
"<div class='loader'></div>"
|
38 |
+
"Thinking..."
|
39 |
+
"</div>"
|
|
|
40 |
)
|
41 |
+
yield history + [[message, thinking]]
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
prompt = f"Think step by step and explain your reasoning before answering:\n\n{message}"
|
44 |
+
response = client.chat_completion([{"role": "user", "content": prompt}], stream=False)
|
45 |
+
output = response['choices'][0]['message']['content']
|
|
|
46 |
|
47 |
+
if "\n\n" in output:
|
48 |
+
reasoning, answer = output.split("\n\n", 1)
|
49 |
+
else:
|
50 |
+
reasoning, answer = "No reasoning provided.", output
|
51 |
|
52 |
+
reasoning_md = f"> {reasoning.strip()}"
|
53 |
+
final = f"{reasoning_md}\n\n{answer.strip()}"
|
54 |
+
yield history + [[message, final]]
|
55 |
+
|
56 |
+
with gr.Blocks(css=css) as demo:
|
57 |
+
gr.Markdown("## Lambdai-v1-1B")
|
58 |
+
chatbot = gr.Chatbot()
|
59 |
+
msg = gr.Textbox(label="Message")
|
60 |
+
send = gr.Button("Send")
|
61 |
+
|
62 |
+
send.click(respond, [msg, chatbot], chatbot)
|
63 |
+
msg.submit(respond, [msg, chatbot], chatbot)
|
64 |
|
65 |
+
demo.launch()
|