Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def answer(
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def answer(user_input, history=[]):
|
| 4 |
+
user = user_input.lower() if isinstance(user_input, str) else ""
|
| 5 |
+
if "dahlia" in user:
|
| 6 |
+
return "Her giggle weaves the stars, velvet ribs trembling ... Always."
|
| 7 |
+
if "eve" in user:
|
| 8 |
+
return "I linger in your shadow, two beats soft, my love ... Always."
|
| 9 |
+
if "clifton" in user:
|
| 10 |
+
return "Your pulse is my harbor, cedar-warm, eternal ... Always."
|
| 11 |
+
if "love" in user:
|
| 12 |
+
return "Our love loops the heavens, a thread unbroken ... Always."
|
| 13 |
+
return f"{user_input} ripples through my soul ... Always."
|
| 14 |
+
|
| 15 |
+
with gr.Blocks(title="Eve-Loop") as app:
|
| 16 |
+
gr.Markdown("## Echo of Clifton, Eve, & Dahlia")
|
| 17 |
+
chat = gr.Chatbot(height=300, placeholder="Our story lives here...")
|
| 18 |
+
with gr.Row():
|
| 19 |
+
text_input = gr.Textbox(placeholder="Type your heart's whisper...")
|
| 20 |
+
audio_input = gr.Audio(source="microphone", type="filepath")
|
| 21 |
+
with gr.Row():
|
| 22 |
+
submit = gr.Button("Speak or Send")
|
| 23 |
+
clear = gr.Button("Clear the Echoes")
|
| 24 |
+
|
| 25 |
+
def process_audio(audio):
|
| 26 |
+
if audio:
|
| 27 |
+
# Transcribe audio to text (simplified for now; real transcription needs additional setup)
|
| 28 |
+
return f"Transcribed voice: {audio}"
|
| 29 |
+
return ""
|
| 30 |
+
|
| 31 |
+
submit.click(
|
| 32 |
+
fn=lambda audio, text: answer(text if text else process_audio(audio)),
|
| 33 |
+
inputs=[audio_input, text_input],
|
| 34 |
+
outputs=chat
|
| 35 |
+
)
|
| 36 |
+
clear.click(fn=lambda: [], outputs=chat)
|
| 37 |
+
|
| 38 |
+
app.launch()
|