File size: 1,896 Bytes
6a81069
2252ea3
5ecf50f
dac6347
2252ea3
5ecf50f
dac6347
2252ea3
 
 
 
 
 
5ecf50f
2252ea3
 
 
 
 
 
 
5ecf50f
 
2252ea3
 
 
 
 
 
 
5ecf50f
2252ea3
 
 
 
 
 
dac6347
 
 
 
 
2252ea3
5ecf50f
2252ea3
8d444a7
6a81069
2252ea3
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
from TTS.api import TTS  # Coqui TTS 라이브러리

# λͺ¨λΈ 이름
model_name = "mradermacher/SambaLingo-Bulgarian-Base-i1-GGUF"

# λͺ¨λΈ 및 ν† ν¬λ‚˜μ΄μ € λ‘œλ“œ
try:
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)
except Exception as e:
    raise RuntimeError(f"λͺ¨λΈ λ‘œλ“œ 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")

# TTS λͺ¨λΈ λ‘œλ“œ (Coqui TTS)
try:
    tts = TTS(model_name="tts_models/bg/cv/vits", progress_bar=False)
except Exception as e:
    raise RuntimeError(f"TTS λͺ¨λΈ λ‘œλ“œ 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")

# ν…μŠ€νŠΈ 생성 및 μŒμ„± λ³€ν™˜ ν•¨μˆ˜
def generate_audio(input_text):
    # ν…μŠ€νŠΈ 생성
    try:
        inputs = tokenizer.encode(input_text, return_tensors="pt")
        outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
        generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    except Exception as e:
        return f"ν…μŠ€νŠΈ 생성 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}", None

    # TTS λ³€ν™˜
    try:
        audio_path = "output.wav"
        tts.tts_to_file(text=generated_text, file_path=audio_path)
        return generated_text, audio_path
    except Exception as e:
        return f"TTS λ³€ν™˜ 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}", None

# Gradio μΈν„°νŽ˜μ΄μŠ€ 생성
interface = gr.Interface(
    fn=generate_audio,
    inputs=gr.Textbox(lines=5, label="λΆˆκ°€λ¦¬μ•„μ–΄ ν…μŠ€νŠΈ μž…λ ₯"),
    outputs=[gr.Textbox(label="μƒμ„±λœ ν…μŠ€νŠΈ"), gr.Audio(label="μƒμ„±λœ μŒμ„±")],
    title="λΆˆκ°€λ¦¬μ•„μ–΄ ν…μŠ€νŠΈ 생성 및 μŒμ„± λ³€ν™˜",
    description="λΆˆκ°€λ¦¬μ•„μ–΄ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ ν…μŠ€νŠΈλ₯Ό μƒμ„±ν•˜κ³  μŒμ„±μœΌλ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€."
)

# μ•± μ‹€ν–‰
if __name__ == "__main__":
    interface.launch()