Spaces:
Sleeping
Sleeping
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()
|