rahulrana0001 commited on
Commit
0144dac
·
1 Parent(s): c444a83

UI: Remove Maya Chat column as requested and stabilize TTS audio buffer format

Browse files
Files changed (2) hide show
  1. app.py +2 -41
  2. pipeline/tts.py +14 -3
app.py CHANGED
@@ -312,33 +312,14 @@ with gr.Blocks(title="Maya: Immersive Manga AI", css=CUSTOM_CSS) as demo:
312
  with gr.Tabs():
313
  with gr.Tab("📖 Comic Reader Mode"):
314
  with gr.Row():
315
- # --- Maya Assistant Sidebar ---
316
- import base64
317
- from maya_var import MAYA_B64
318
- maya_path = "maya_ui.png"
319
- try:
320
- with open(maya_path, "wb") as f:
321
- f.write(base64.b64decode(MAYA_B64.split(",")[1]))
322
- except: pass
323
-
324
- with gr.Column(scale=1, min_width=180, elem_classes=["glass"]):
325
- maya_img = gr.Image(value=maya_path, label="Maya", interactive=False)
326
- maya_chat_log = gr.Markdown("Maya: *உங்களுக்காக காத்திருக்கிறேன்...* ❤️", elem_id="maya_chat_log")
327
- maya_chat_input = gr.Textbox(placeholder="Message Maya...", show_label=False, container=False)
328
- maya_talk_btn = gr.Button("Talk to Maya ❤️", size="sm", variant="primary")
329
- maya_audio = gr.Audio(visible=False, autoplay=True, elem_id="maya_audio_player")
330
-
331
- gr.Markdown("---")
332
- gr.Markdown("<small>Press 'B' for Panic Mode</small>")
333
-
334
- with gr.Column(scale=4, min_width=300, elem_classes=["glass"]):
335
  comic_display = gr.Image(label="Comic Page", type="filepath", height=600, elem_id="main_comic")
336
  with gr.Row():
337
  prev_btn = gr.Button("⬅️ Prev", scale=1)
338
  page_status = gr.Label(value="Upload PDF", scale=2)
339
  next_btn = gr.Button("Next ➡️", scale=1)
340
 
341
- with gr.Column(scale=3, min_width=300, elem_classes=["glass"]):
342
  with gr.Group():
343
  gr.Markdown("### ⚙️ Master Settings")
344
  comic_upload = gr.File(label="Upload (PDF/EPUB)", file_types=[".pdf", ".epub"], height=80)
@@ -405,26 +386,6 @@ with gr.Blocks(title="Maya: Immersive Manga AI", css=CUSTOM_CSS) as demo:
405
  out_text = gr.Textbox(label="Original Text (Cleaned)", lines=5)
406
  out_tamil = gr.Textbox(label="Tamil Translation", lines=5)
407
  out_audio = gr.Audio(label="Audio Output")
408
-
409
- # --- Maya Assistant Logic ---
410
- def maya_chat(msg, level):
411
- if not msg or len(msg.strip()) < 1:
412
- return gr.update(), ""
413
- response = get_maya_response(msg, level)
414
- return response, ""
415
-
416
- def maya_speaks(level):
417
- # Trigger an intelligent greeting based on mood
418
- msg = "Hi Maya, enna panre?"
419
- response = get_maya_response(msg, level)
420
- txt = response.replace("Maya: *", "").replace("*", "")
421
-
422
- voice = "Soft & Seductive (Maya)" if level > 50 else "Cheerful (Maya)"
423
- aud = generate_tamil_speech(txt, voice)
424
- return response, aud
425
-
426
- maya_talk_btn.click(maya_speaks, inputs=[heat_level], outputs=[maya_chat_log, maya_audio])
427
- maya_chat_input.submit(maya_chat, inputs=[maya_chat_input, heat_level], outputs=[maya_chat_log, maya_chat_input], show_progress="hidden")
428
 
429
  # --- Dynamic Temperature & Heartbeat Speed Logic ---
430
  def update_mood(level, bgm):
 
312
  with gr.Tabs():
313
  with gr.Tab("📖 Comic Reader Mode"):
314
  with gr.Row():
315
+ with gr.Column(scale=5, min_width=300, elem_classes=["glass"]):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  comic_display = gr.Image(label="Comic Page", type="filepath", height=600, elem_id="main_comic")
317
  with gr.Row():
318
  prev_btn = gr.Button("⬅️ Prev", scale=1)
319
  page_status = gr.Label(value="Upload PDF", scale=2)
320
  next_btn = gr.Button("Next ➡️", scale=1)
321
 
322
+ with gr.Column(scale=4, min_width=300, elem_classes=["glass"]):
323
  with gr.Group():
324
  gr.Markdown("### ⚙️ Master Settings")
325
  comic_upload = gr.File(label="Upload (PDF/EPUB)", file_types=[".pdf", ".epub"], height=80)
 
386
  out_text = gr.Textbox(label="Original Text (Cleaned)", lines=5)
387
  out_tamil = gr.Textbox(label="Tamil Translation", lines=5)
388
  out_audio = gr.Audio(label="Audio Output")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
 
390
  # --- Dynamic Temperature & Heartbeat Speed Logic ---
391
  def update_mood(level, bgm):
pipeline/tts.py CHANGED
@@ -38,10 +38,21 @@ class TamilTTS:
38
  try:
39
  await communicate.save(tmp_path)
40
  data, samplerate = sf.read(tmp_path)
41
- return samplerate, data
42
- finally:
43
- if os.path.exists(tmp_path):
 
 
44
  os.remove(tmp_path)
 
 
 
 
 
 
 
 
 
45
 
46
  # Persistent loop to avoid file descriptor conflicts
47
  _GLOBAL_LOOP = None
 
38
  try:
39
  await communicate.save(tmp_path)
40
  data, samplerate = sf.read(tmp_path)
41
+ # Ensure it's a writable float32 array for Gradio
42
+ audio_data = np.array(data, dtype='float32')
43
+
44
+ # Cleanup temp file
45
+ try:
46
  os.remove(tmp_path)
47
+ except: pass
48
+
49
+ return samplerate, audio_data
50
+ except Exception as e:
51
+ print(f"TTS GENERATION ERROR: {e}")
52
+ if os.path.exists(tmp_path):
53
+ try: os.remove(tmp_path)
54
+ except: pass
55
+ raise e
56
 
57
  # Persistent loop to avoid file descriptor conflicts
58
  _GLOBAL_LOOP = None