thak123 commited on
Commit
c778bde
·
1 Parent(s): 2724867

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -33
app.py CHANGED
@@ -82,56 +82,77 @@ import gradio as gr
82
  import requests
83
  from PIL import Image
84
 
85
- def display_item(index, list_of_items):
86
- """Displays a single item from a list of items.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- Args:
 
 
 
89
  index: The index of the item to display.
90
  list_of_items: A list of Python dictionaries, where each dictionary has the following keys:
91
  * text: The text.
92
  * image_url: The URL of the image.
93
  * translation: The translation of the text.
94
  * link: The URL of the website link.
95
- """
96
-
97
- # Get the item from the list of items
98
- item = list_of_items[index]
99
-
100
- # Display the text
101
- gr.Text(item["text"])
102
-
103
- # Display the image
104
- image = Image.open(requests.get(item["image_url"], stream=True).raw)
105
- gr.Image(image)
106
-
107
- # Display the translation
108
- gr.Text(item["translation"])
109
-
110
- # Display the website link
111
- gr.Button("View website", onclick=lambda: gr.HTML(f"<iframe src='{item['link']}' width='100%' height='500px'></iframe>"))
112
 
113
  # Define a function to show the next item
114
  def show_next_item(index, list_of_items):
115
  """Shows the next item in the list of items.
116
-
117
- Args:
118
  index: The current index.
119
  list_of_items: A list of Python dictionaries, where each dictionary has the following keys:
120
  * text: The text.
121
  * image_url: The URL of the image.
122
  * translation: The translation of the text.
123
  * link: The URL of the website link.
124
- """
125
-
126
- # Increment the index
127
- index += 1
128
-
129
- # If the index is greater than the length of the list of items, then reset the index to 0
130
- if index >= len(list_of_items):
131
- index = 0
132
-
133
- # Display the next item
134
- display_item(index, list_of_items)
135
 
136
  # Create a Gradio interface
137
  interface = gr.Interface(display_item, inputs=["number", "list"], outputs="html")
 
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
  """Shows the next item in the list of items.
137
+
138
+ Args:
139
  index: The current index.
140
  list_of_items: A list of Python dictionaries, where each dictionary has the following keys:
141
  * text: The text.
142
  * image_url: The URL of the image.
143
  * translation: The translation of the text.
144
  * link: The URL of the website link.
145
+ """
146
+
147
+ # Increment the index
148
+ index += 1
149
+
150
+ # If the index is greater than the length of the list of items, then reset the index to 0
151
+ if index >= len(list_of_items):
152
+ index = 0
153
+
154
+ # Display the next item
155
+ display_item(index, list_of_items)
156
 
157
  # Create a Gradio interface
158
  interface = gr.Interface(display_item, inputs=["number", "list"], outputs="html")