Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import random
|
3 |
import nltk
|
4 |
from nltk.corpus import wordnet
|
5 |
-
|
6 |
import requests
|
7 |
|
8 |
# Download the Croatian WordNet data
|
@@ -48,7 +48,7 @@ def get_definition_and_image(word):
|
|
48 |
# URL for the ImageNet API
|
49 |
base_url = "http://www.image-net.org/api/text/imagenet.synset.geturls?wnid="
|
50 |
|
51 |
-
#
|
52 |
url = base_url + synset_id
|
53 |
|
54 |
# Send a GET request to the URL
|
@@ -86,7 +86,9 @@ def sample_word_and_display_info():
|
|
86 |
return image_url ,definition
|
87 |
else:
|
88 |
print(f"No information found for '{word}'")
|
89 |
-
|
|
|
|
|
90 |
|
91 |
|
92 |
|
@@ -94,8 +96,15 @@ def sample():
|
|
94 |
return sample_word_and_display_info()
|
95 |
|
96 |
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
|
101 |
|
|
|
2 |
import random
|
3 |
import nltk
|
4 |
from nltk.corpus import wordnet
|
5 |
+
from PIL import Image
|
6 |
import requests
|
7 |
|
8 |
# Download the Croatian WordNet data
|
|
|
48 |
# URL for the ImageNet API
|
49 |
base_url = "http://www.image-net.org/api/text/imagenet.synset.geturls?wnid="
|
50 |
|
51 |
+
# Cofrom PIL import Image mbine the base URL and the synset ID to get a list of image URLs
|
52 |
url = base_url + synset_id
|
53 |
|
54 |
# Send a GET request to the URL
|
|
|
86 |
return image_url ,definition
|
87 |
else:
|
88 |
print(f"No information found for '{word}'")
|
89 |
+
|
90 |
+
img = Image.New(‘RGB’, (64,64) )
|
91 |
+
return img, "No information found for '{word}'"
|
92 |
|
93 |
|
94 |
|
|
|
96 |
return sample_word_and_display_info()
|
97 |
|
98 |
|
99 |
+
with gr.Blocks() as demo:
|
100 |
+
image, text sample_word_and_display_info()
|
101 |
+
gr.Image(image)
|
102 |
+
gr.Markdown(text)
|
103 |
+
|
104 |
+
demo.launch()
|
105 |
+
|
106 |
+
# iface = gr.Interface(fn=sample, inputs="text", outputs="image, text")
|
107 |
+
# iface.launch()
|
108 |
|
109 |
|
110 |
|