Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
from TTS.api import TTS
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
#
|
22 |
-
def generate_audio(input_text):
|
23 |
-
try:
|
24 |
-
# ν
μ€νΈ μμ±
|
25 |
-
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
26 |
-
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
27 |
-
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
28 |
-
except Exception as e:
|
29 |
-
return f"ν
μ€νΈ μμ± μ€ λ¬Έμ κ° λ°μνμ΅λλ€: {e}", None
|
30 |
-
|
31 |
-
try:
|
32 |
-
# TTS λ³ν
|
33 |
-
audio_path = "output.wav"
|
34 |
-
tts.tts_to_file(text=generated_text, file_path=audio_path)
|
35 |
-
return generated_text, audio_path
|
36 |
-
except Exception as e:
|
37 |
-
return f"TTS λ³ν μ€ λ¬Έμ κ° λ°μνμ΅λλ€: {e}", None
|
38 |
-
|
39 |
-
# Gradio μΈν°νμ΄μ€ μμ±
|
40 |
-
interface = gr.Interface(
|
41 |
-
fn=generate_audio,
|
42 |
-
inputs=gr.Textbox(lines=5, label="ν
μ€νΈ μ
λ ₯"),
|
43 |
-
outputs=[gr.Textbox(label="μμ±λ ν
μ€νΈ"), gr.Audio(label="μμ±λ μμ±")],
|
44 |
-
title="LLaMA 7B ν
μ€νΈ μμ± λ° μμ± λ³ν",
|
45 |
-
description="ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ μμ±λ ν
μ€νΈλ₯Ό μΆλ ₯νκ³ μμ±μΌλ‘ λ³νν©λλ€."
|
46 |
-
)
|
47 |
-
|
48 |
-
# μ± μ€ν
|
49 |
if __name__ == "__main__":
|
50 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Step 1: Initialize the text-generation pipeline
|
5 |
+
pipe = pipeline("text-generation", model="sambanovasystems/SambaLingo-Bulgarian-Base")
|
6 |
|
7 |
+
# Step 2: Define a function to generate Bulgarian text and convert it to TTS
|
8 |
+
def generate_and_speak(prompt):
|
9 |
+
# Generate text using the model
|
10 |
+
generated_text = pipe(prompt, max_length=50, num_return_sequences=1)[0]["generated_text"]
|
11 |
+
|
12 |
+
# Placeholder: Simulating TTS (you can replace this with an actual TTS library)
|
13 |
+
# Install a TTS library such as gTTS for better implementation
|
14 |
+
from gtts import gTTS
|
15 |
+
tts = gTTS(generated_text, lang="bg")
|
16 |
+
audio_file = "output.mp3"
|
17 |
+
tts.save(audio_file)
|
18 |
+
|
19 |
+
return generated_text, audio_file
|
20 |
|
21 |
+
# Step 3: Create Gradio interface
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("## Bulgarian Text Generator and TTS")
|
24 |
+
with gr.Row():
|
25 |
+
input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
|
26 |
+
with gr.Column():
|
27 |
+
output_text = gr.Textbox(label="Generated Text")
|
28 |
+
output_audio = gr.Audio(label="Generated Speech", type="file")
|
29 |
+
generate_button = gr.Button("Generate")
|
30 |
+
|
31 |
+
generate_button.click(generate_and_speak, inputs=input_prompt, outputs=[output_text, output_audio])
|
32 |
|
33 |
+
# Run the app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
if __name__ == "__main__":
|
35 |
+
demo.launch()
|