Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,8 @@ import edge_tts
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import scipy.io.wavfile
|
| 7 |
-
import asyncio
|
| 8 |
-
import numpy as np
|
| 9 |
from transformers import pipeline
|
| 10 |
|
| 11 |
-
# [ν΅μ¬] λΉλκΈ° νμΌ λμ€ν¬λ¦½ν° μλ¬ λ°©μ§ μ€μ
|
| 12 |
-
if os.name != 'nt': # 리λ
μ€/λ§₯ νκ²½ λμ
|
| 13 |
-
import selectors
|
| 14 |
-
selector = selectors.SelectSelector()
|
| 15 |
-
try:
|
| 16 |
-
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
| 17 |
-
except:
|
| 18 |
-
pass
|
| 19 |
-
|
| 20 |
GENAI_KEY = os.getenv("GEMINI_KEY")
|
| 21 |
|
| 22 |
# μμ
λͺ¨λΈ λ‘λ
|
|
@@ -70,17 +59,17 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 70 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 71 |
music_p = music_match.group(1).strip() if music_match else "rock guitar riff"
|
| 72 |
|
| 73 |
-
# μμ± μμ±
|
| 74 |
tts_final = "\n".join(clean_text.split('\n')[:5])
|
| 75 |
voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
|
| 76 |
-
# νμΌμ΄ μ΄λ €μλμ§ νμΈ ν μμ±
|
| 77 |
communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', tts_final), member_data['voice'])
|
| 78 |
await communicate.save(voice_path)
|
| 79 |
|
| 80 |
-
# μμ
μμ±
|
| 81 |
music_path = None
|
| 82 |
if music_synthesiser:
|
| 83 |
try:
|
|
|
|
| 84 |
safe_p = music_p.lower()
|
| 85 |
if any(x in safe_p for x in ['laugh', 'vocal', 'voice', 'human']):
|
| 86 |
safe_p = "heavy rock electric guitar riff"
|
|
@@ -95,13 +84,13 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 95 |
return tts_final, voice_path, music_path, tab_display
|
| 96 |
|
| 97 |
except Exception as e:
|
| 98 |
-
print(f"Error caught: {e}")
|
| 99 |
return f"System Overload: {str(e)}", None, None, "Error"
|
| 100 |
|
| 101 |
with gr.Blocks() as demo:
|
|
|
|
| 102 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|
| 103 |
o1 = gr.Textbox(); o2 = gr.Audio(); o3 = gr.Audio(); o4 = gr.Textbox()
|
| 104 |
btn = gr.Button("GO"); btn.click(band_consulting, [i1, i2, i3], [o1, o2, o3, o4], api_name="predict")
|
| 105 |
|
| 106 |
-
# ν μμ€ν
|
| 107 |
-
demo.queue().launch()
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import scipy.io.wavfile
|
|
|
|
|
|
|
| 7 |
from transformers import pipeline
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
GENAI_KEY = os.getenv("GEMINI_KEY")
|
| 10 |
|
| 11 |
# μμ
λͺ¨λΈ λ‘λ
|
|
|
|
| 59 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 60 |
music_p = music_match.group(1).strip() if music_match else "rock guitar riff"
|
| 61 |
|
| 62 |
+
# μμ± μμ±
|
| 63 |
tts_final = "\n".join(clean_text.split('\n')[:5])
|
| 64 |
voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
|
|
|
|
| 65 |
communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', tts_final), member_data['voice'])
|
| 66 |
await communicate.save(voice_path)
|
| 67 |
|
| 68 |
+
# μμ
μμ±
|
| 69 |
music_path = None
|
| 70 |
if music_synthesiser:
|
| 71 |
try:
|
| 72 |
+
# νν° λ¨μ΄ μ°ν λ° κΈΈμ΄ μ‘°μ (12μ΄)
|
| 73 |
safe_p = music_p.lower()
|
| 74 |
if any(x in safe_p for x in ['laugh', 'vocal', 'voice', 'human']):
|
| 75 |
safe_p = "heavy rock electric guitar riff"
|
|
|
|
| 84 |
return tts_final, voice_path, music_path, tab_display
|
| 85 |
|
| 86 |
except Exception as e:
|
|
|
|
| 87 |
return f"System Overload: {str(e)}", None, None, "Error"
|
| 88 |
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
+
# API μ μ© μ΅μ UI (λͺ¨λ λ‘μ§μ predictλ‘ μ°κ²°)
|
| 91 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|
| 92 |
o1 = gr.Textbox(); o2 = gr.Audio(); o3 = gr.Audio(); o4 = gr.Textbox()
|
| 93 |
btn = gr.Button("GO"); btn.click(band_consulting, [i1, i2, i3], [o1, o2, o3, o4], api_name="predict")
|
| 94 |
|
| 95 |
+
# ν μμ€ν
μ μ μ©νλ ssr_modeλ Falseλ‘ μ€μ νμ¬ asyncio μλ¬ λ°©μ§
|
| 96 |
+
demo.queue().launch(ssr_mode=False)
|