FIRSTSPACE / app.py
ProPerNounpYK's picture
Update app.py
3adb62b verified
import gradio as gr
import os
from gtts import gTTS
import pygame
def text_to_speech(text):
pygame.init()
pygame.mixer.init()
tts = gTTS(text=text, lang="ko")
tts.save("output.mp3")
pygame.mixer.music.load("output.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
iface = gr.Interface(
fn=text_to_speech,
inputs="text",
outputs="audio",
title="GTTS ๊ธฐ๋ฐ˜ ํ•œ๊ธ€ ์Œ์„ฑ ๋ณ€ํ™˜",
description="ํ…์ŠคํŠธ๋ฅผ ์Œ์„ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค."
)
iface.launch()
import os
import torch
from transformers import pipeline
from gtts import gTTS
import pygame
from huggingface_hub import HfApi, ModelRepository
api = HfApi()
repo_id = api.create_repo("codepilot/gtts-ko", exist_ok=True)
repo = ModelRepository(repo_id, clone_from_local=True)
torch.save({"model": "gtts-ko"}, os.path.join(repo.local_dir, "pytorch_model.bin"))
with open(os.path.join(repo.local_dir, "requirements.txt"), "w") as f:
f.write("gtts\npygame\ngradio\ntorch\ntransformers\nhuggingface_hub\nanyio")
with open(os.path.join(repo.local_dir, "app.py"), "w") as f:
f.write("""
import gradio as gr
import os
from gtts import gTTS
import pygame
def text_to_speech(text):
pygame.init()
pygame.mixer.init()
tts = gTTS(text=text, lang="ko")
tts.save("output.mp3")
pygame.mixer.music.load("output.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
iface = gr.Interface(
fn=text_to_speech,
inputs="text",
outputs="audio",
title="GTTS ๊ธฐ๋ฐ˜ ํ•œ๊ธ€ ์Œ์„ฑ ๋ณ€ํ™˜",
description="ํ…์ŠคํŠธ๋ฅผ ์Œ์„ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค."
)
iface.launch()
""")
repo.push_to_hub()