File size: 2,460 Bytes
0a45abf
 
 
 
 
 
 
 
b625031
 
 
 
 
 
 
 
0a45abf
 
 
 
b625031
 
 
 
 
 
 
 
0a45abf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
from gtts import gTTS
from PIL import Image
import requests
from io import BytesIO

# Manually add definitions
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."
}

# Corresponding image URLs (example URLs, replace with actual GitHub links)
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]
    
    # Get the image
    image_url = image_urls[word]
    response = requests.get(image_url)
    img = Image.open(BytesIO(response.content))
    img = img.resize((400, 250))  # Resize to half size
    
    # Generate the audio
    tts = gTTS(text=definition, lang='en', tld='co.uk', slow=False)
    audio_file = f"{word}.mp3"
    tts.save(audio_file)
    
    return img, audio_file

# Create the Gradio interface
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"
)

# Launch the interface
iface.launch(debug=True)