thak123 commited on
Commit
6954df4
1 Parent(s): 1110548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -78
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # import gradio as gr
2
 
3
  # # Define a list of word and translation pairs
4
  # word_translations = [
@@ -8,29 +8,50 @@
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
@@ -78,74 +99,55 @@
78
  # # Launch the Gradio interface
79
  # iface.launch()
80
 
81
- import gradio as gr
82
- import requests
83
- from PIL import Image
 
84
 
85
- list_of_items = [
86
- {
87
- "text": "Hello",
88
- "image_url": "https://example.com/image1.jpg",
89
- "translation": "Hola",
90
- "link": "https://www.google.com/"
91
- },
92
- {
93
- "text": "World",
94
- "image_url": "https://example.com/image2.jpg",
95
- "translation": "Mundo",
96
- "link": "https://en.wikipedia.org/wiki/World"
97
- },
98
- {
99
- "text": "Goodbye",
100
- "image_url": "https://example.com/image3.jpg",
101
- "translation": "Adi贸s",
102
- "link": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
103
- }
104
- ]
105
 
106
- def display_item(index, list_of_items):
107
- """Displays a single item from a list of items.
108
 
109
- Args:
110
- index: The index of the item to display.
111
- list_of_items: A list of Python dictionaries, where each dictionary has the following keys:
112
- * text: The text.
113
- * image_url: The URL of the image.
114
- * translation: The translation of the text.
115
- * link: The URL of the website link.
116
- """
117
 
118
- # Get the item from the list of items
119
- item = list_of_items[index]
120
 
121
- # Display the text
122
- gr.Text(item["text"])
123
 
124
- # Display the image
125
- image = Image.open(requests.get(item["image_url"], stream=True).raw)
126
- gr.Image(image)
127
 
128
- # Display the translation
129
- gr.Text(item["translation"])
130
 
131
- # Display the website link
132
- gr.Button("View website", onclick=lambda: gr.HTML(f"<iframe src='{item['link']}' width='100%' height='500px'></iframe>"))
133
 
134
- # Define a function to show the next item
135
- def show_next_item(index, list_of_items):
136
- index += 1
137
 
138
- # If the index is greater than the length of the list of items, then reset the index to 0
139
- if index >= len(list_of_items):
140
- index = 0
141
 
142
- # Display the next item
143
- display_item(index, list_of_items)
144
 
145
- # Create a Gradio interface
146
- interface = gr.Interface(display_item, inputs=["number", "list"], outputs="html")
147
 
148
- # Launch the Gradio interface
149
- # interface.launch(index=0, list_of_items=list_of_items, show_next_item=show_next_item)
150
- interface.launch()
151
 
 
1
+ import gradio as gr
2
 
3
  # # Define a list of word and translation pairs
4
  # word_translations = [
 
8
  # {"word": "Please", "translation": "Por favor"}
9
  # ]
10
 
11
+ word_translations = [
12
+ {
13
+ "text": "Hello",
14
+ "image_url": "https://example.com/image1.jpg",
15
+ "translation": "Hola",
16
+ "link": "https://www.google.com/"
17
+ },
18
+ {
19
+ "text": "World",
20
+ "image_url": "https://example.com/image2.jpg",
21
+ "translation": "Mundo",
22
+ "link": "https://en.wikipedia.org/wiki/World"
23
+ },
24
+ {
25
+ "text": "Goodbye",
26
+ "image_url": "https://example.com/image3.jpg",
27
+ "translation": "Adi贸s",
28
+ "link": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
29
+ }
30
+ ]
31
 
32
+ # Initialize an index to keep track of the current word
33
+ current_index = 0
 
 
 
 
34
 
35
+ # Function to display the current word and translation
36
+ def display_word():
37
+ global current_index
38
+ word_translation = word_translations[current_index]
39
+ current_index = (current_index + 1) % len(word_translations)
40
+ return f"Word: {word_translation['word']}<br>Translation: {word_translation['translation']} {gr.HTML(f"<iframe src=\'{item['link']}\' width='100%' height='500px'></iframe>"))}"
 
 
 
 
41
 
42
+ # Create a Gradio interface
43
+ iface = gr.Interface(
44
+ fn=display_word,
45
+ live=True,
46
+ title="Word Translation App",
47
+ description="Click 'Next' to view the next word and translation.",
48
+ inputs=[],
49
+ outputs=["html"],
50
+ layout="vertical"
51
+ )
52
+
53
+ # Start the Gradio interface
54
+ iface.launch()
55
 
56
  # import gradio as gr
57
  # import random
 
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