Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,47 +79,63 @@
|
|
| 79 |
# iface.launch()
|
| 80 |
|
| 81 |
import gradio as gr
|
| 82 |
-
import
|
| 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 |
# Create a Gradio interface
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 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 |
|
|
|
|
| 79 |
# iface.launch()
|
| 80 |
|
| 81 |
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")
|
| 138 |
+
|
| 139 |
+
# Launch the Gradio interface
|
| 140 |
+
interface.launch(index=0, list_of_items=list_of_items, show_next_item=show_next_item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|