File size: 1,618 Bytes
581eff5
 
fca7c1b
581eff5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import torch
# Project 1: Bilingual Story Generation
english_story_generator = pipeline("text-generation", model="gpt2")
arabic_story_generator = pipeline("text-generation", model="aubmindlab/arabert")

def generate_story(prompt, language):
    if language == "English":
        return english_story_generator(prompt, max_length=200)[0]['generated_text']
    else:  # Arabic
        return arabic_story_generator(prompt, max_length=200)[0]['generated_text']

# Project 2: Bilingual Text-to-Speech
english_tts = pipeline("text-to-speech", model="facebook/tts_transformer")
arabic_tts = pipeline("text-to-speech", model="google/arabic_tts")

def text_to_speech(text, language):
    if language == "English":
        audio = english_tts(text)
    else:  # Arabic
        audio = arabic_tts(text)
    return audio

# Gradio Interface
with gr.Blocks() as demo:
    with gr.Row():
        language_choice = gr.Radio(choices=["English", "Arabic"], label="Select Language")
        prompt_input = gr.Textbox(label="Enter a story prompt")
        generate_button = gr.Button("Generate Story")
    
    story_output = gr.Textbox(label="Generated Story", interactive=False)
    
    generate_button.click(generate_story, inputs=[prompt_input, language_choice], outputs=story_output)
    
    tts_input = gr.Textbox(label="Paste your story for TTS")
    tts_button = gr.Button("Read Story Aloud")
    audio_output = gr.Audio(label="Audio Output", type="numpy")
    
    tts_button.click(text_to_speech, inputs=[tts_input, language_choice], outputs=audio_output)

demo.launch()