Spaces:
Sleeping
Sleeping
pokemon image
Browse files
app.py
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
def get_image(pokemon_name):
|
| 7 |
+
response = requests.get(f'https://pokeapi.co/api/v2/pokemon/{pokemon_name}')
|
| 8 |
+
data = response.json()
|
| 9 |
+
image_url = data['sprites']['other']['official-artwork']['front_default']
|
| 10 |
+
|
| 11 |
+
image_response = requests.get(image_url)
|
| 12 |
+
image = Image.open(io.BytesIO(image_response.content))
|
| 13 |
+
return image
|
| 14 |
|
| 15 |
+
iface = gr.Interface(fn=get_image, inputs="text", outputs="image")
|
| 16 |
iface.launch()
|