|
import gradio as gr |
|
from gtts import gTTS |
|
from PIL import Image |
|
import requests |
|
from io import BytesIO |
|
|
|
|
|
word_definitions = { |
|
"quaint": "Having an old-fashioned or unusual quality or appearance that is usually attractive or appealing.", |
|
"explore": "To travel over or through (a place) in order to learn more about it or to find something.", |
|
"cheerful": "Feeling or showing happiness.", |
|
"peddler": "Someone who sells things in small amounts often by traveling to different places.", |
|
"curious": "Having a desire to learn or know more about something or someone.", |
|
"enthusiasm": "Strong excitement about something; a strong feeling of active interest in something that you like or enjoy.", |
|
"skeptical": "Having or expressing doubt about something.", |
|
"whisper": "To speak very softly or quietly." |
|
} |
|
|
|
|
|
image_urls = { |
|
"quaint": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/001.png", |
|
"explore": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/002.png", |
|
"cheerful": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/003.png", |
|
"peddler": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/004.png", |
|
"curious": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/005.png", |
|
"enthusiasm": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/006.png", |
|
"skeptical": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/007.png", |
|
"whisper": "https://raw.githubusercontent.com/PAMUS-JP30/flashcard/main/008.png" |
|
} |
|
|
|
def generate_output(word): |
|
definition = word + "." + "It means" + word_definitions[word] |
|
|
|
|
|
image_url = image_urls[word] |
|
response = requests.get(image_url) |
|
img = Image.open(BytesIO(response.content)) |
|
img = img.resize((400, 250)) |
|
|
|
|
|
tts = gTTS(text=definition, lang='en', tld='co.uk', slow=False) |
|
audio_file = f"{word}.mp3" |
|
tts.save(audio_file) |
|
|
|
return img, audio_file |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_output, |
|
inputs=gr.Dropdown(choices=list(word_definitions.keys()), label="Choose a word"), |
|
outputs=[gr.Image(type="pil"), gr.Audio(type="filepath", autoplay=True)], |
|
title="Word Definition with Image and Audio" |
|
) |
|
|
|
|
|
iface.launch(debug=True) |