File size: 3,893 Bytes
905bb30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae4ea47
905bb30
3e994a1
905bb30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42d0feb
 
905bb30
 
 
 
42d0feb
 
 
905bb30
 
 
 
 
 
 
 
 
42d0feb
 
a36aeae
905bb30
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# import gradio as gr

# # Define a list of word and translation pairs
# word_translations = [
#     {"word": "Hello", "translation": "Hola"},
#     {"word": "Goodbye", "translation": "Adiós"},
#     {"word": "Thank you", "translation": "Gracias"},
#     {"word": "Please", "translation": "Por favor"}
# ]

# # Initialize an index to keep track of the current word
# current_index = 0

# # Function to display the current word and translation
# def display_word():
#     global current_index
#     word_translation = word_translations[current_index]
#     current_index = (current_index + 1) % len(word_translations)
#     return f"Word: {word_translation['word']}<br>Translation: {word_translation['translation']}"

# # Create a Gradio interface
# iface = gr.Interface(
#     fn=display_word,
#     live=True,
#     title="Word Translation App",
#     description="Click 'Next' to view the next word and translation.",
#     inputs=[],
#     outputs=["html"],
#     layout="vertical"
# )

# # Start the Gradio interface
# iface.launch()

# import gradio as gr
# import random

# # Define your list of words and their translations
# word_translations = [
#     {"word": "Apple", "translation": "Manzana", "image_url": "apple_image.jpg"},
#     {"word": "Banana", "translation": "Plátano", "image_url": "banana_image.jpg"},
#     {"word": "Orange", "translation": "Naranja", "image_url": "orange_image.jpg"},
#     # Add more words and translations as needed
# ]

# # Initialize a variable to keep track of the current word index
# current_word_index = 0

# # Define a function to display the current word and translation
# def display_word():
#     word_info = word_translations[current_word_index]
#     word = word_info["word"]
#     translation = word_info["translation"]
#     image_url = word_info["image_url"]
#     return f"Word: {word}<br>Translation: {translation}<br><img src='{image_url}' width='200'>"

# # Define a function to handle the "Next" button click
# def next_word():
#     global current_word_index
#     current_word_index = (current_word_index + 1) % len(word_translations)
#     return display_word()

# # Create a Gradio interface
# iface = gr.Interface(
#     fn=display_word,
#     live=True,
#     title="Word Translation App",
#     description="Click 'Next' to view the next word and translation.",
#     inputs=[],
#     outputs="html",
#     layout="vertical",
#     wide=True
# )

# # Add a "Next" button to the interface
# iface.add_button("Next", next_word)

# # Launch the Gradio interface
# iface.launch()

import gradio as gr
import random

# Sample data
data = [
    {
        'word': 'Apple',
        'image_url': 'https://example.com/apple.jpg',
        'translation': 'Manzana',
        'website_link': 'https://en.wikipedia.org/wiki/Apple'
    },
    {
        'word': 'Banana',
        'image_url': 'https://example.com/banana.jpg',
        'translation': 'Plátano',
        'website_link': 'https://en.wikipedia.org/wiki/Banana'
    },
    {
        'word': 'Cherry',
        'image_url': 'https://example.com/cherry.jpg',
        'translation': 'Cereza',
        'website_link': 'https://en.wikipedia.org/wiki/Cherry'
    }
]

# Function to display data for a given index
def display_data(index):
    word_data = data[index]
    return f"Word: {word_data['word']}\nTranslation: {word_data['translation']}", word_data['image_url'], word_data['website_link']

# Create a Gradio interface
iface = gr.Interface(
    display_data, 
    [
        gr.Component(label="Word and Translation", type="text", name="word_translation"),
        gr.Component(label="Image", type="image", name="image"),
        gr.Component(label="Website Link", type="text", name="website_link"),
    ],
    live=False,  # To avoid auto-refresh when input changes
    examples=[(0,), (1,), (2,)],  # Provide initial examples
    title="Word Display App"
)

iface.launch()