first commit
Browse files- .DS_Store +0 -0
- .gitignore +3 -0
- app.py +66 -0
- requirements.txt +72 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
resources.py
|
2 |
+
**venv
|
3 |
+
**flagged
|
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import gradio as gr
|
3 |
+
import json
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
+
from resources import HF_ACCESS_TOKEN
|
7 |
+
|
8 |
+
def fetch_image(url):
|
9 |
+
try:
|
10 |
+
# Fetch the image from the provided URL
|
11 |
+
response = requests.get(url)
|
12 |
+
image = Image.open(BytesIO(response.content))
|
13 |
+
return image, response
|
14 |
+
except Exception as e:
|
15 |
+
return None
|
16 |
+
|
17 |
+
def url_to_image(url):
|
18 |
+
image, message = fetch_image(url)
|
19 |
+
if image:
|
20 |
+
return image, message
|
21 |
+
else:
|
22 |
+
return "Invalid URL or Unable to Fetch Image"
|
23 |
+
|
24 |
+
def caption (url):
|
25 |
+
#url = "https://1779092274.rsc.cdn77.org/temp/1714987285_ab89b05ca8071c563d50c6d85a7fdcbd.jpg"
|
26 |
+
|
27 |
+
image, desc = url_to_image(url)#requests.get(url=url)
|
28 |
+
|
29 |
+
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
|
30 |
+
headers = {"Authorization": "Bearer "+HF_ACCESS_TOKEN}
|
31 |
+
print("Status code:",desc.status_code)
|
32 |
+
|
33 |
+
if desc.status_code == 200:
|
34 |
+
|
35 |
+
print("Image downloaded successfully")
|
36 |
+
response = requests.post(API_URL, headers=headers, data=desc)
|
37 |
+
else:
|
38 |
+
print("Failed to download image")
|
39 |
+
|
40 |
+
return image,json.loads(response.text)[0]["generated_text"]
|
41 |
+
|
42 |
+
text_input = gr.Textbox(
|
43 |
+
label="URL",
|
44 |
+
info="Image's URL",
|
45 |
+
lines=5,
|
46 |
+
value="https://1779092274.rsc.cdn77.org/temp/1714987285_ab89b05ca8071c563d50c6d85a7fdcbd.jpg"
|
47 |
+
)
|
48 |
+
text_output = gr.Textbox(
|
49 |
+
label="Description",
|
50 |
+
info="Image's Description",
|
51 |
+
lines=5,
|
52 |
+
value=""
|
53 |
+
)
|
54 |
+
image_output = gr.Image(label="Output Image")
|
55 |
+
|
56 |
+
demo = gr.Interface(
|
57 |
+
fn=caption,
|
58 |
+
description= "Get the description for this image",
|
59 |
+
inputs=[text_input],
|
60 |
+
outputs=[image_output, text_output],
|
61 |
+
title="Image Description Assistante",
|
62 |
+
#capture_session=True
|
63 |
+
)
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.3.0
|
3 |
+
annotated-types==0.6.0
|
4 |
+
anyio==4.3.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.2.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
contourpy==1.2.1
|
10 |
+
cycler==0.12.1
|
11 |
+
dnspython==2.6.1
|
12 |
+
email_validator==2.1.1
|
13 |
+
fastapi==0.111.0
|
14 |
+
fastapi-cli==0.0.2
|
15 |
+
ffmpy==0.3.2
|
16 |
+
filelock==3.14.0
|
17 |
+
fonttools==4.51.0
|
18 |
+
fsspec==2024.3.1
|
19 |
+
gradio==4.29.0
|
20 |
+
gradio_client==0.16.1
|
21 |
+
h11==0.14.0
|
22 |
+
httpcore==1.0.5
|
23 |
+
httptools==0.6.1
|
24 |
+
httpx==0.27.0
|
25 |
+
huggingface-hub==0.23.0
|
26 |
+
idna==3.7
|
27 |
+
importlib_resources==6.4.0
|
28 |
+
Jinja2==3.1.4
|
29 |
+
jsonschema==4.22.0
|
30 |
+
jsonschema-specifications==2023.12.1
|
31 |
+
kiwisolver==1.4.5
|
32 |
+
markdown-it-py==3.0.0
|
33 |
+
MarkupSafe==2.1.5
|
34 |
+
matplotlib==3.8.4
|
35 |
+
mdurl==0.1.2
|
36 |
+
numpy==1.26.4
|
37 |
+
orjson==3.10.3
|
38 |
+
packaging==24.0
|
39 |
+
pandas==2.2.2
|
40 |
+
pillow==10.3.0
|
41 |
+
pydantic==2.7.1
|
42 |
+
pydantic_core==2.18.2
|
43 |
+
pydub==0.25.1
|
44 |
+
Pygments==2.18.0
|
45 |
+
pyparsing==3.1.2
|
46 |
+
python-dateutil==2.9.0.post0
|
47 |
+
python-dotenv==1.0.1
|
48 |
+
python-multipart==0.0.9
|
49 |
+
pytz==2024.1
|
50 |
+
PyYAML==6.0.1
|
51 |
+
referencing==0.35.1
|
52 |
+
requests==2.31.0
|
53 |
+
rich==13.7.1
|
54 |
+
rpds-py==0.18.1
|
55 |
+
ruff==0.4.3
|
56 |
+
semantic-version==2.10.0
|
57 |
+
shellingham==1.5.4
|
58 |
+
six==1.16.0
|
59 |
+
sniffio==1.3.1
|
60 |
+
starlette==0.37.2
|
61 |
+
tomlkit==0.12.0
|
62 |
+
toolz==0.12.1
|
63 |
+
tqdm==4.66.4
|
64 |
+
typer==0.12.3
|
65 |
+
typing_extensions==4.11.0
|
66 |
+
tzdata==2024.1
|
67 |
+
ujson==5.9.0
|
68 |
+
urllib3==2.2.1
|
69 |
+
uvicorn==0.29.0
|
70 |
+
uvloop==0.19.0
|
71 |
+
watchfiles==0.21.0
|
72 |
+
websockets==11.0.3
|