CoolFace
Apppublic

MsMc24/FLASHCARDS

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py57 linesDownload Raw Back to root
1import gradio as gr2from gtts import gTTS3from PIL import Image4import requests5from io import BytesIO6 7# Manually add definitions8word_definitions = {9    "vibrant": "Full of energy or colorful",10    "dismissed": "Sent away or rejected",11    "depicting": "Showing or representing",12    "admired": "Regarded with respect.",13    "anxious": "worried or nervous.",14    "skeptics": "people who question or doubt.",15    "achievement": "success",16    "thrilled": "excitement and happiness"17}18 19# Corresponding image URLs (example URLs, replace with actual GitHub links)20image_urls = {21    "vibrant": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.001.png",22    "dismissed": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.002.png",23    "depicting": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.003.png",24    "admired": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.004.png",25    "anxious": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.005.png",26    "skeptics": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.006.png",27    "achievement": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.007.png",28    "thrilled": "https://github.com/MK316/Spring2024/raw/main/DLTESOL/project/flashcard.008.png"29}30 31def generate_output(word):32    definition = word + "." + "It means" + word_definitions[word]33 34    # Get the image35    image_url = image_urls[word]36    response = requests.get(image_url)37    img = Image.open(BytesIO(response.content))38    img = img.resize((400, 250))  # Resize to half size39 40    # Generate the audio41    tts = gTTS(text=definition, lang='en', tld='co.uk', slow=False)42    audio_file = f"{word}.mp3"43    tts.save(audio_file)44 45    return img, audio_file46 47# Create the Gradio interface48iface = gr.Interface(49    fn=generate_output,50    inputs=gr.Dropdown(choices=list(word_definitions.keys()), label="Choose a word"),51    outputs=[gr.Image(type="pil"), gr.Audio(type="filepath", autoplay=True)],52    title="Word Definition with Image and Audio"53)54 55# Launch the interface56iface.launch(debug=True)57