Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
{
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
]
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
def display_word():
|
16 |
-
global current_index
|
17 |
-
word_translation = word_translations[current_index]
|
18 |
-
current_index = (current_index + 1) % len(word_translations)
|
19 |
-
return f"Word: {word_translation['word']}<br>Translation: {word_translation['translation']}"
|
20 |
|
21 |
# Create a Gradio interface
|
22 |
iface = gr.Interface(
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
)
|
31 |
|
32 |
-
# Start the Gradio interface
|
33 |
iface.launch()
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
|
3 |
+
# # Define a list of word and translation pairs
|
4 |
+
# word_translations = [
|
5 |
+
# {"word": "Hello", "translation": "Hola"},
|
6 |
+
# {"word": "Goodbye", "translation": "Adi贸s"},
|
7 |
+
# {"word": "Thank you", "translation": "Gracias"},
|
8 |
+
# {"word": "Please", "translation": "Por favor"}
|
9 |
+
# ]
|
10 |
+
|
11 |
+
# # Initialize an index to keep track of the current word
|
12 |
+
# current_index = 0
|
13 |
+
|
14 |
+
# # Function to display the current word and translation
|
15 |
+
# def display_word():
|
16 |
+
# global current_index
|
17 |
+
# word_translation = word_translations[current_index]
|
18 |
+
# current_index = (current_index + 1) % len(word_translations)
|
19 |
+
# return f"Word: {word_translation['word']}<br>Translation: {word_translation['translation']}"
|
20 |
+
|
21 |
+
# # Create a Gradio interface
|
22 |
+
# iface = gr.Interface(
|
23 |
+
# fn=display_word,
|
24 |
+
# live=True,
|
25 |
+
# title="Word Translation App",
|
26 |
+
# description="Click 'Next' to view the next word and translation.",
|
27 |
+
# inputs=[],
|
28 |
+
# outputs=["html"],
|
29 |
+
# layout="vertical"
|
30 |
+
# )
|
31 |
+
|
32 |
+
# # Start the Gradio interface
|
33 |
+
# iface.launch()
|
34 |
+
|
35 |
+
# import gradio as gr
|
36 |
+
# import random
|
37 |
+
|
38 |
+
# # Define your list of words and their translations
|
39 |
+
# word_translations = [
|
40 |
+
# {"word": "Apple", "translation": "Manzana", "image_url": "apple_image.jpg"},
|
41 |
+
# {"word": "Banana", "translation": "Pl谩tano", "image_url": "banana_image.jpg"},
|
42 |
+
# {"word": "Orange", "translation": "Naranja", "image_url": "orange_image.jpg"},
|
43 |
+
# # Add more words and translations as needed
|
44 |
+
# ]
|
45 |
+
|
46 |
+
# # Initialize a variable to keep track of the current word index
|
47 |
+
# current_word_index = 0
|
48 |
+
|
49 |
+
# # Define a function to display the current word and translation
|
50 |
+
# def display_word():
|
51 |
+
# word_info = word_translations[current_word_index]
|
52 |
+
# word = word_info["word"]
|
53 |
+
# translation = word_info["translation"]
|
54 |
+
# image_url = word_info["image_url"]
|
55 |
+
# return f"Word: {word}<br>Translation: {translation}<br><img src='{image_url}' width='200'>"
|
56 |
+
|
57 |
+
# # Define a function to handle the "Next" button click
|
58 |
+
# def next_word():
|
59 |
+
# global current_word_index
|
60 |
+
# current_word_index = (current_word_index + 1) % len(word_translations)
|
61 |
+
# return display_word()
|
62 |
+
|
63 |
+
# # Create a Gradio interface
|
64 |
+
# iface = gr.Interface(
|
65 |
+
# fn=display_word,
|
66 |
+
# live=True,
|
67 |
+
# title="Word Translation App",
|
68 |
+
# description="Click 'Next' to view the next word and translation.",
|
69 |
+
# inputs=[],
|
70 |
+
# outputs="html",
|
71 |
+
# layout="vertical",
|
72 |
+
# wide=True
|
73 |
+
# )
|
74 |
+
|
75 |
+
# # Add a "Next" button to the interface
|
76 |
+
# iface.add_button("Next", next_word)
|
77 |
+
|
78 |
+
# # Launch the Gradio interface
|
79 |
+
# iface.launch()
|
80 |
+
|
81 |
import gradio as gr
|
82 |
+
import random
|
83 |
|
84 |
+
# Sample data
|
85 |
+
data = [
|
86 |
+
{
|
87 |
+
'word': 'Apple',
|
88 |
+
'image_url': 'https://example.com/apple.jpg',
|
89 |
+
'translation': 'Manzana',
|
90 |
+
'website_link': 'https://en.wikipedia.org/wiki/Apple'
|
91 |
+
},
|
92 |
+
{
|
93 |
+
'word': 'Banana',
|
94 |
+
'image_url': 'https://example.com/banana.jpg',
|
95 |
+
'translation': 'Pl谩tano',
|
96 |
+
'website_link': 'https://en.wikipedia.org/wiki/Banana'
|
97 |
+
},
|
98 |
+
{
|
99 |
+
'word': 'Cherry',
|
100 |
+
'image_url': 'https://example.com/cherry.jpg',
|
101 |
+
'translation': 'Cereza',
|
102 |
+
'website_link': 'https://en.wikipedia.org/wiki/Cherry'
|
103 |
+
}
|
104 |
]
|
105 |
|
106 |
+
# Function to display data for a given index
|
107 |
+
def display_data(index):
|
108 |
+
word_data = data[index]
|
109 |
+
return f"Word: {word_data['word']}\nTranslation: {word_data['translation']}", word_data['image_url'], word_data['website_link']
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
# Create a Gradio interface
|
112 |
iface = gr.Interface(
|
113 |
+
display_data,
|
114 |
+
[
|
115 |
+
gr.Component(label="Word and Translation", type="text", name="word_translation"),
|
116 |
+
gr.Component(label="Image", type="image", name="image"),
|
117 |
+
gr.Component(label="Website Link", type="text", name="website_link"),
|
118 |
+
],
|
119 |
+
live=False, # To avoid auto-refresh when input changes
|
120 |
+
examples=[(0,), (1,), (2,)], # Provide initial examples
|
121 |
+
title="Word Display App"
|
122 |
)
|
123 |
|
|
|
124 |
iface.launch()
|
125 |
+
|