Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
client = InferenceClient("cosmosai471/Luna-v2")
|
5 |
|
6 |
def respond(
|
7 |
message,
|
@@ -11,38 +9,23 @@ def respond(
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
21 |
-
|
22 |
-
messages.append({"role": "user", "content": message})
|
23 |
-
|
24 |
-
response = ""
|
25 |
-
for msg in client.chat_completion(
|
26 |
-
messages,
|
27 |
-
max_tokens=max_tokens,
|
28 |
-
stream=True,
|
29 |
-
temperature=temperature,
|
30 |
-
top_p=top_p,
|
31 |
-
):
|
32 |
-
token = msg.choices[0].delta.content or ""
|
33 |
-
response += token
|
34 |
-
yield response
|
35 |
|
36 |
demo = gr.ChatInterface(
|
37 |
fn=respond,
|
38 |
additional_inputs=[
|
39 |
-
gr.Textbox(value="You are a helpful
|
40 |
-
gr.Slider(minimum=
|
41 |
-
gr.Slider(minimum=0.1, maximum=
|
42 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
43 |
],
|
44 |
-
title="Luna AI
|
45 |
-
description="
|
46 |
theme="default"
|
47 |
)
|
48 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from lunacode import smart_luna_answer
|
|
|
|
|
3 |
|
4 |
def respond(
|
5 |
message,
|
|
|
9 |
temperature,
|
10 |
top_p,
|
11 |
):
|
12 |
+
# We won't stream but return full output for simplicity
|
13 |
+
try:
|
14 |
+
result = smart_luna_answer(message, max_tokens=max_tokens, temperature=temperature, top_p=top_p)
|
15 |
+
return result
|
16 |
+
except Exception as e:
|
17 |
+
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
demo = gr.ChatInterface(
|
20 |
fn=respond,
|
21 |
additional_inputs=[
|
22 |
+
gr.Textbox(value="You are a helpful AI assistant.", label="System message"),
|
23 |
+
gr.Slider(minimum=128, maximum=2048, value=512, step=1, label="Max new tokens"),
|
24 |
+
gr.Slider(minimum=0.1, maximum=1.5, value=0.7, step=0.1, label="Temperature"),
|
25 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
26 |
],
|
27 |
+
title="Luna AI — Code & Web Enhanced Assistant",
|
28 |
+
description="Ask Luna questions, generate code, and explore smart AI-powered answers with web context!",
|
29 |
theme="default"
|
30 |
)
|
31 |
|