Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def fetch_tags(image_url):
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return '[ERROR]: Invalid image URL format.', '', '', ''
|
| 14 |
|
| 15 |
base_url = 'https://danbooru.donmai.us/posts'
|
| 16 |
response = requests.get(f'{base_url}/{image_id}.json')
|
|
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
import gradio as gr
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
|
| 7 |
def fetch_tags(image_url):
|
| 8 |
+
# Try to extract the image ID from the URL
|
| 9 |
+
match = re.search(r'https://danbooru.donmai.us/posts/(\d+)', image_url)
|
| 10 |
+
if not match:
|
| 11 |
+
return '[ERROR]: Invalid image URL format. Please use a valid Danbooru URL.', '', '', ''
|
| 12 |
+
|
| 13 |
+
image_id = match.group(1) # Extract image ID from URL
|
|
|
|
| 14 |
|
| 15 |
base_url = 'https://danbooru.donmai.us/posts'
|
| 16 |
response = requests.get(f'{base_url}/{image_id}.json')
|