sayaka1 commited on
Commit
a5548af
·
verified ·
1 Parent(s): 34b0d79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -8,15 +8,15 @@ def fetch_tags(image_url):
8
  try:
9
  image_id = image_url.split('/')[-1].split('.')[0]
10
  if not image_id.isdigit():
11
- return '[ERROR]: Invalid image URL format.'
12
  except IndexError:
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')
17
 
18
  if response.status_code != 200:
19
- return f'[ERROR]: {response.status_code} - Failed to retrieve data.'
20
 
21
  data = json.loads(response.text)
22
 
@@ -26,17 +26,10 @@ def fetch_tags(image_url):
26
  tags = data.get('tag_string_general', '')
27
 
28
  # Prepare prompt and formatted tags
29
- prompt = f'{character} {origin} {tags}'
30
  formatted_tags = tags.replace(" ", ", ")
31
- formatted_prompt = prompt.replace(" ", ", ")
32
 
33
- # Display the results
34
- return {
35
- "Character": character,
36
- "Origin": origin,
37
- "Tags": formatted_tags,
38
- "Prompt": formatted_prompt
39
- }
40
 
41
 
42
  # Create a Gradio interface
@@ -49,8 +42,8 @@ iface = gr.Interface(
49
  gr.Textbox(label="Tags (comma-separated)"),
50
  gr.Textbox(label="Prompt (comma-separated)")
51
  ],
52
- title="Danbooru Tag Fetcher",
53
- description="Enter a Danbooru image URL to fetch character, origin, tags, and prompt information."
54
  )
55
 
56
  # Launch the interface
 
8
  try:
9
  image_id = image_url.split('/')[-1].split('.')[0]
10
  if not image_id.isdigit():
11
+ return '[ERROR]: Invalid image URL format.', '', '', ''
12
  except IndexError:
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')
17
 
18
  if response.status_code != 200:
19
+ return f'[ERROR]: {response.status_code} - Failed to retrieve data.', '', '', ''
20
 
21
  data = json.loads(response.text)
22
 
 
26
  tags = data.get('tag_string_general', '')
27
 
28
  # Prepare prompt and formatted tags
 
29
  formatted_tags = tags.replace(" ", ", ")
30
+ prompt = f'{character}, {origin}, {formatted_tags}'
31
 
32
+ return character, origin, formatted_tags, prompt
 
 
 
 
 
 
33
 
34
 
35
  # Create a Gradio interface
 
42
  gr.Textbox(label="Tags (comma-separated)"),
43
  gr.Textbox(label="Prompt (comma-separated)")
44
  ],
45
+ title="Danbooru Tag Extractor",
46
+ description="Enter a Danbooru image URL to fetch and format character, origin, tags, and prompt information."
47
  )
48
 
49
  # Launch the interface