Spaces:
Sleeping
Sleeping
Daniel Ecer commited on
Commit ·
d63a7ac
1
Parent(s): a0aa138
Added pollinations
Browse files
fngradio_various_api_mcp/apis/pollinations.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from io import BytesIO
|
| 2 |
+
from typing import Annotated
|
| 3 |
+
import urllib.parse
|
| 4 |
+
|
| 5 |
+
import PIL.Image
|
| 6 |
+
from fngradio import FnGradioApp
|
| 7 |
+
import httpx
|
| 8 |
+
from pydantic import Field
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
app = FnGradioApp()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@app.interface()
|
| 15 |
+
def generate_image_using_pollinations(
|
| 16 |
+
prompt: Annotated[
|
| 17 |
+
str,
|
| 18 |
+
Field(min_length=5)
|
| 19 |
+
]
|
| 20 |
+
) -> PIL.Image.Image:
|
| 21 |
+
"""
|
| 22 |
+
Generate image using `pollinations.ai`
|
| 23 |
+
"""
|
| 24 |
+
encoded_prompt = urllib.parse.quote(prompt)
|
| 25 |
+
response = httpx.get(
|
| 26 |
+
f'https://image.pollinations.ai/prompt/{encoded_prompt}'
|
| 27 |
+
)
|
| 28 |
+
response.raise_for_status()
|
| 29 |
+
image = PIL.Image.open(BytesIO(response.read()))
|
| 30 |
+
return image
|
fngradio_various_api_mcp/app.py
CHANGED
|
@@ -6,6 +6,7 @@ from fngradio_various_api_mcp.apis import (
|
|
| 6 |
numbersapi,
|
| 7 |
picsum,
|
| 8 |
placebear,
|
|
|
|
| 9 |
zenquotes
|
| 10 |
)
|
| 11 |
|
|
@@ -16,5 +17,6 @@ app = FnGradioApp(apps=[
|
|
| 16 |
numbersapi.app,
|
| 17 |
picsum.app,
|
| 18 |
placebear.app,
|
|
|
|
| 19 |
zenquotes.app
|
| 20 |
])
|
|
|
|
| 6 |
numbersapi,
|
| 7 |
picsum,
|
| 8 |
placebear,
|
| 9 |
+
pollinations,
|
| 10 |
zenquotes
|
| 11 |
)
|
| 12 |
|
|
|
|
| 17 |
numbersapi.app,
|
| 18 |
picsum.app,
|
| 19 |
placebear.app,
|
| 20 |
+
pollinations.app,
|
| 21 |
zenquotes.app
|
| 22 |
])
|