Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,45 @@
|
|
1 |
import gradio as gr
|
2 |
-
from lunacode import smart_luna_answer
|
3 |
-
|
4 |
-
def respond(
|
5 |
-
message,
|
6 |
-
history: list[tuple[str, str]],
|
7 |
-
system_message,
|
8 |
-
max_tokens,
|
9 |
-
):
|
10 |
try:
|
11 |
result = smart_luna_answer(message, max_tokens=max_tokens)
|
12 |
return result
|
13 |
except Exception as e:
|
14 |
return f"Error: {str(e)}"
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
fn=respond,
|
18 |
additional_inputs=[
|
19 |
gr.Textbox(value="You are a helpful AI assistant.", label="System message"),
|
@@ -21,7 +47,12 @@ demo = gr.ChatInterface(
|
|
21 |
],
|
22 |
title="Luna AI — Code & Web Enhanced Assistant",
|
23 |
description="Ask Luna questions, generate code, and explore smart AI-powered answers with web context!",
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
)
|
26 |
|
27 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
from lunacode import smart_luna_answer, text_to_speech_luna
|
3 |
+
|
4 |
+
def respond(message, history, system_message, max_tokens):
|
|
|
|
|
|
|
|
|
|
|
5 |
try:
|
6 |
result = smart_luna_answer(message, max_tokens=max_tokens)
|
7 |
return result
|
8 |
except Exception as e:
|
9 |
return f"Error: {str(e)}"
|
10 |
|
11 |
+
def voice_chat(audio, max_tokens):
|
12 |
+
import speech_recognition as sr
|
13 |
+
recognizer = sr.Recognizer()
|
14 |
+
|
15 |
+
with sr.AudioFile(audio) as source:
|
16 |
+
audio_data = recognizer.record(source)
|
17 |
+
try:
|
18 |
+
text = recognizer.recognize_google(audio_data)
|
19 |
+
except:
|
20 |
+
return "Could not understand audio", None
|
21 |
+
|
22 |
+
response_text = smart_luna_answer(text, max_tokens=max_tokens)
|
23 |
+
audio_path = text_to_speech_luna(response_text)
|
24 |
+
return response_text, audio_path
|
25 |
+
|
26 |
+
# Voice tab
|
27 |
+
voice_interface = gr.Interface(
|
28 |
+
fn=voice_chat,
|
29 |
+
inputs=[
|
30 |
+
gr.Audio(source="microphone", type="filepath", label="Speak to Luna"),
|
31 |
+
gr.Slider(minimum=128, maximum=2048, value=512, step=1, label="Max new tokens")
|
32 |
+
],
|
33 |
+
outputs=[
|
34 |
+
gr.Textbox(label="Luna's Response"),
|
35 |
+
gr.Audio(label="Luna Speaks")
|
36 |
+
],
|
37 |
+
title="Luna Voice Assistant",
|
38 |
+
description="Speak to Luna and hear her response!",
|
39 |
+
)
|
40 |
+
|
41 |
+
# Text chat
|
42 |
+
chat_interface = gr.ChatInterface(
|
43 |
fn=respond,
|
44 |
additional_inputs=[
|
45 |
gr.Textbox(value="You are a helpful AI assistant.", label="System message"),
|
|
|
47 |
],
|
48 |
title="Luna AI — Code & Web Enhanced Assistant",
|
49 |
description="Ask Luna questions, generate code, and explore smart AI-powered answers with web context!",
|
50 |
+
)
|
51 |
+
|
52 |
+
# Tabs
|
53 |
+
demo = gr.TabbedInterface(
|
54 |
+
[chat_interface, voice_interface],
|
55 |
+
["Chat with Luna", "Voice with Luna"]
|
56 |
)
|
57 |
|
58 |
if __name__ == "__main__":
|