bori0824 commited on
Commit
0a45abf
1 Parent(s): b360a24

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ from PIL import Image
4
+ import requests
5
+ from io import BytesIO
6
+
7
+ # Manually add definitions
8
+ word_definitions = {
9
+ "vibrant": "Full of energy, 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)
20
+ image_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
+
31
+ def generate_output(word):
32
+ definition = word + "." + "It means" + word_definitions[word]
33
+
34
+ # Get the image
35
+ 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 size
39
+
40
+ # Generate the audio
41
+ 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_file
46
+
47
+ # Create the Gradio interface
48
+ iface = 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 interface
56
+ iface.launch(debug=True)