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()