File size: 1,305 Bytes
6a81069
4ba54ec
dac6347
4ba54ec
 
dac6347
4ba54ec
 
 
 
 
 
 
 
 
 
 
 
5ecf50f
4ba54ec
 
 
 
 
 
 
5241203
4ba54ec
 
 
2252ea3
4ba54ec
2252ea3
4ba54ec
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
import gradio as gr
from transformers import pipeline

# Step 1: Initialize the text-generation pipeline
pipe = pipeline("text-generation", model="sambanovasystems/SambaLingo-Bulgarian-Base")

# Step 2: Define a function to generate Bulgarian text and convert it to TTS
def generate_and_speak(prompt):
    # Generate text using the model
    generated_text = pipe(prompt, max_length=50, num_return_sequences=1)[0]["generated_text"]
    
    # Placeholder: Simulating TTS (you can replace this with an actual TTS library)
    from gtts import gTTS
    tts = gTTS(generated_text, lang="bg")
    audio_file = "output.mp3"
    tts.save(audio_file)
    
    return generated_text, audio_file

# Step 3: Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("## Bulgarian Text Generator and TTS")
    with gr.Row():
        input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
        with gr.Column():
            output_text = gr.Textbox(label="Generated Text")
            output_audio = gr.Audio(label="Generated Speech", type="filepath")  # Changed "file" to "filepath"
    generate_button = gr.Button("Generate")
    
    generate_button.click(generate_and_speak, inputs=input_prompt, outputs=[output_text, output_audio])

# Run the app
if __name__ == "__main__":
    demo.launch()