Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,24 @@
|
|
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 |
word_translations = [
|
12 |
{
|
13 |
-
"
|
14 |
"image_url": "https://example.com/image1.jpg",
|
15 |
"translation": "Hola",
|
16 |
"link": "https://www.google.com/"
|
17 |
},
|
18 |
{
|
19 |
-
"
|
20 |
"image_url": "https://example.com/image2.jpg",
|
21 |
"translation": "Mundo",
|
22 |
"link": "https://en.wikipedia.org/wiki/World"
|
23 |
},
|
24 |
{
|
25 |
-
"
|
26 |
"image_url": "https://example.com/image3.jpg",
|
27 |
"translation": "Adi贸s",
|
28 |
-
"link": "https://
|
29 |
}
|
30 |
]
|
31 |
|
@@ -53,101 +46,4 @@ iface = gr.Interface(
|
|
53 |
# Start the Gradio interface
|
54 |
iface.launch()
|
55 |
|
56 |
-
# import gradio as gr
|
57 |
-
# import random
|
58 |
-
|
59 |
-
# # Define your list of words and their translations
|
60 |
-
# word_translations = [
|
61 |
-
# {"word": "Apple", "translation": "Manzana", "image_url": "apple_image.jpg"},
|
62 |
-
# {"word": "Banana", "translation": "Pl谩tano", "image_url": "banana_image.jpg"},
|
63 |
-
# {"word": "Orange", "translation": "Naranja", "image_url": "orange_image.jpg"},
|
64 |
-
# # Add more words and translations as needed
|
65 |
-
# ]
|
66 |
-
|
67 |
-
# # Initialize a variable to keep track of the current word index
|
68 |
-
# current_word_index = 0
|
69 |
-
|
70 |
-
# # Define a function to display the current word and translation
|
71 |
-
# def display_word():
|
72 |
-
# word_info = word_translations[current_word_index]
|
73 |
-
# word = word_info["word"]
|
74 |
-
# translation = word_info["translation"]
|
75 |
-
# image_url = word_info["image_url"]
|
76 |
-
# return f"Word: {word}<br>Translation: {translation}<br><img src='{image_url}' width='200'>"
|
77 |
-
|
78 |
-
# # Define a function to handle the "Next" button click
|
79 |
-
# def next_word():
|
80 |
-
# global current_word_index
|
81 |
-
# current_word_index = (current_word_index + 1) % len(word_translations)
|
82 |
-
# return display_word()
|
83 |
-
|
84 |
-
# # Create a Gradio interface
|
85 |
-
# iface = gr.Interface(
|
86 |
-
# fn=display_word,
|
87 |
-
# live=True,
|
88 |
-
# title="Word Translation App",
|
89 |
-
# description="Click 'Next' to view the next word and translation.",
|
90 |
-
# inputs=[],
|
91 |
-
# outputs="html",
|
92 |
-
# layout="vertical",
|
93 |
-
# wide=True
|
94 |
-
# )
|
95 |
-
|
96 |
-
# # Add a "Next" button to the interface
|
97 |
-
# iface.add_button("Next", next_word)
|
98 |
-
|
99 |
-
# # Launch the Gradio interface
|
100 |
-
# iface.launch()
|
101 |
-
|
102 |
-
# import gradio as gr
|
103 |
-
# import requests
|
104 |
-
# from PIL import Image
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
# def display_item(index, list_of_items):
|
109 |
-
# """Displays a single item from a list of items.
|
110 |
-
|
111 |
-
# Args:
|
112 |
-
# index: The index of the item to display.
|
113 |
-
# list_of_items: A list of Python dictionaries, where each dictionary has the following keys:
|
114 |
-
# * text: The text.
|
115 |
-
# * image_url: The URL of the image.
|
116 |
-
# * translation: The translation of the text.
|
117 |
-
# * link: The URL of the website link.
|
118 |
-
# """
|
119 |
-
|
120 |
-
# # Get the item from the list of items
|
121 |
-
# item = list_of_items[index]
|
122 |
-
|
123 |
-
# # Display the text
|
124 |
-
# gr.Text(item["text"])
|
125 |
-
|
126 |
-
# # Display the image
|
127 |
-
# image = Image.open(requests.get(item["image_url"], stream=True).raw)
|
128 |
-
# gr.Image(image)
|
129 |
-
|
130 |
-
# # Display the translation
|
131 |
-
# gr.Text(item["translation"])
|
132 |
-
|
133 |
-
# # Display the website link
|
134 |
-
# gr.Button("View website", onclick=lambda: gr.HTML(f"<iframe src='{item['link']}' width='100%' height='500px'></iframe>"))
|
135 |
-
|
136 |
-
# # Define a function to show the next item
|
137 |
-
# def show_next_item(index, list_of_items):
|
138 |
-
# index += 1
|
139 |
-
|
140 |
-
# # If the index is greater than the length of the list of items, then reset the index to 0
|
141 |
-
# if index >= len(list_of_items):
|
142 |
-
# index = 0
|
143 |
-
|
144 |
-
# # Display the next item
|
145 |
-
# display_item(index, list_of_items)
|
146 |
-
|
147 |
-
# # Create a Gradio interface
|
148 |
-
# interface = gr.Interface(display_item, inputs=["number", "list"], outputs="html")
|
149 |
-
|
150 |
-
# # Launch the Gradio interface
|
151 |
-
# # interface.launch(index=0, list_of_items=list_of_items, show_next_item=show_next_item)
|
152 |
-
# interface.launch()
|
153 |
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# # Define a list of word and translation pairs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
word_translations = [
|
5 |
{
|
6 |
+
"word": "Hello",
|
7 |
"image_url": "https://example.com/image1.jpg",
|
8 |
"translation": "Hola",
|
9 |
"link": "https://www.google.com/"
|
10 |
},
|
11 |
{
|
12 |
+
"word": "World",
|
13 |
"image_url": "https://example.com/image2.jpg",
|
14 |
"translation": "Mundo",
|
15 |
"link": "https://en.wikipedia.org/wiki/World"
|
16 |
},
|
17 |
{
|
18 |
+
"word": "Goodbye",
|
19 |
"image_url": "https://example.com/image3.jpg",
|
20 |
"translation": "Adi贸s",
|
21 |
+
"link": "https://en.wikipedia.org/wiki/Bat"
|
22 |
}
|
23 |
]
|
24 |
|
|
|
46 |
# Start the Gradio interface
|
47 |
iface.launch()
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|