Severian commited on
Commit
56cac7d
·
verified ·
1 Parent(s): 0976a62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -24
app.py CHANGED
@@ -202,6 +202,10 @@ def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str,
202
  """
203
  Generate a caption, training prompt, tags, or a style prompt for image generation based on the input image and parameters.
204
  """
 
 
 
 
205
  torch.cuda.empty_cache()
206
 
207
  try:
@@ -345,7 +349,7 @@ film_stocks_info = {
345
  "Ektar": "Modern Kodak film. Color photos with little to no grain. Results look like regular modern photography with artistic angles.",
346
  "Film Washi": "Mostly black and white photos with fine/low to moderate grain. Occasionally gives colored photos with low saturation. Distinct style with high black contrast and soft camera lens effect.",
347
  "Fomapan": "Black and white photos with fine/low to moderate grain, highly artistic exposure and angles. Adds very soft lens effect without distortion, dark photo vignette.",
348
- "Fujicolor": "Color photos with fine/low to moderate grain. Colors are slightly or notably desaturated, with entire color hue shifted in a very distinct manner.",
349
  "Holga": "Color photos with high grain. Colors are either very oversaturated or slightly desaturated. Distinct contrast of black. Often applies photographic vignette.",
350
  "Instax": "Instant color photos similar to Polaroid but clearer. Near perfect colors, regular saturation, fine/low to medium grain.",
351
  "Lomography": "Color photos with high grain. Colors are either very oversaturated or slightly desaturated. Distinct contrast of black. Often applies photographic vignette.",
@@ -423,33 +427,38 @@ def get_dropdown_choices(info_dict):
423
  # Gradio interface
424
  with gr.Blocks(theme="Hev832/Applio", css=css, fill_width=True, fill_height=True) as demo:
425
  with gr.Tab("Welcome"):
426
- gr.Markdown(
427
- """
428
- <img src="https://cdn-uploads.huggingface.co/production/uploads/64740cf7485a7c8e1bd51ac9/LVZnwLV43UUvKu3HORqSs.webp" alt="UDG" width="250" style="max-width: 100%; height: auto;">
 
 
429
 
430
- # 🎨 Underground Digital's Caption Captain: AI-Powered Art Inspiration
431
 
432
- ## Accelerate Your Creative Workflow with Intelligent Image Analysis
433
 
434
- This innovative tool empowers Yamamoto's artists to quickly generate descriptive captions,<br>
435
- training prompts, and tags from existing artwork, fueling the creative process for GenAI models.
436
 
437
- ## 🚀 How It Works:
438
- 1. **Upload Your Inspiration**: Drop in an image (e.g., a charcoal horse picture) that embodies your desired style.
439
- 2. **Choose Your Output**: Select from descriptive captions, training prompts, or tags.
440
- 3. **Customize the Results**: Adjust tone, length, and other parameters to fine-tune the output.
441
- 4. **Generate and Iterate**: Click 'Caption' to analyze your image and use the results to inspire new creations.
442
- """
443
- )
444
 
445
- with gr.Row():
446
- username = gr.Textbox(label="Username", placeholder="Enter your username", value="ugd", visible=False)
447
- with gr.Row():
448
- password = gr.Textbox(label="Password", type="password", placeholder="Enter your password", value="ugd!", visible=False)
449
- with gr.Row():
450
- login_button = gr.Button("Login", size="sm", visible=False)
451
- login_message = gr.Markdown(visible=False)
452
-
 
 
 
453
  with gr.Tab("Caption Captain") as app_container:
454
  with gr.Accordion("How to Use Caption Captain", open=False):
455
  gr.Markdown("""
@@ -521,6 +530,7 @@ with gr.Blocks(theme="Hev832/Applio", css=css, fill_width=True, fill_height=True
521
 
522
 
523
  with gr.Column():
 
524
  output_caption = gr.Textbox(label="Generated Caption")
525
  run_button = gr.Button("Make My Caption!")
526
 
@@ -563,7 +573,18 @@ with gr.Blocks(theme="Hev832/Applio", css=css, fill_width=True, fill_height=True
563
 
564
  caption_type.change(update_style_options, inputs=[caption_type], outputs=[advanced_options])
565
 
566
- run_button.click(fn=stream_chat, inputs=[input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition_style, lighting_aspect, special_technique, color_effect], outputs=[output_caption])
 
 
 
 
 
 
 
 
 
 
 
567
 
568
 
569
  if __name__ == "__main__":
 
202
  """
203
  Generate a caption, training prompt, tags, or a style prompt for image generation based on the input image and parameters.
204
  """
205
+ # Check if an image has been uploaded
206
+ if input_image is None:
207
+ return "Error: Please upload an image before generating a caption."
208
+
209
  torch.cuda.empty_cache()
210
 
211
  try:
 
349
  "Ektar": "Modern Kodak film. Color photos with little to no grain. Results look like regular modern photography with artistic angles.",
350
  "Film Washi": "Mostly black and white photos with fine/low to moderate grain. Occasionally gives colored photos with low saturation. Distinct style with high black contrast and soft camera lens effect.",
351
  "Fomapan": "Black and white photos with fine/low to moderate grain, highly artistic exposure and angles. Adds very soft lens effect without distortion, dark photo vignette.",
352
+ "Fujicolor": "Color photos with fine/low to moderate grain. Colors are either very oversaturated or slightly desaturated, with entire color hue shifted in a very distinct manner.",
353
  "Holga": "Color photos with high grain. Colors are either very oversaturated or slightly desaturated. Distinct contrast of black. Often applies photographic vignette.",
354
  "Instax": "Instant color photos similar to Polaroid but clearer. Near perfect colors, regular saturation, fine/low to medium grain.",
355
  "Lomography": "Color photos with high grain. Colors are either very oversaturated or slightly desaturated. Distinct contrast of black. Often applies photographic vignette.",
 
427
  # Gradio interface
428
  with gr.Blocks(theme="Hev832/Applio", css=css, fill_width=True, fill_height=True) as demo:
429
  with gr.Tab("Welcome"):
430
+ with gr.Row():
431
+ with gr.Column(scale=2):
432
+ gr.Markdown(
433
+ """
434
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64740cf7485a7c8e1bd51ac9/LVZnwLV43UUvKu3HORqSs.webp" alt="UDG" width="250" style="max-width: 100%; height: auto;">
435
 
436
+ # 🎨 Underground Digital's Caption Captain: AI-Powered Art Inspiration
437
 
438
+ ## Accelerate Your Creative Workflow with Intelligent Image Analysis
439
 
440
+ This innovative tool empowers Yamamoto's artists to quickly generate descriptive captions,<br>
441
+ training prompts, and tags from existing artwork, fueling the creative process for GenAI models.
442
 
443
+ ## 🚀 How It Works:
444
+ 1. **Upload Your Inspiration**: Drop in an image (e.g., a charcoal horse picture) that embodies your desired style.
445
+ 2. **Choose Your Output**: Select from descriptive captions, training prompts, or tags.
446
+ 3. **Customize the Results**: Adjust tone, length, and other parameters to fine-tune the output.
447
+ 4. **Generate and Iterate**: Click 'Caption' to analyze your image and use the results to inspire new creations.
448
+ """
449
+ )
450
 
451
+ with gr.Column(scale=1):
452
+ with gr.Row():
453
+ gr.Markdown(
454
+ """
455
+ Login below using the Yamamoto internal<br>
456
+ username and password to access the full app.<br>
457
+
458
+ Once logged in, a new tab will appear named<br>
459
+ "QR Code Art Generator" allowing you to access.
460
+ """
461
+ )
462
  with gr.Tab("Caption Captain") as app_container:
463
  with gr.Accordion("How to Use Caption Captain", open=False):
464
  gr.Markdown("""
 
530
 
531
 
532
  with gr.Column():
533
+ error_message = gr.Markdown(visible=False) # Add this line
534
  output_caption = gr.Textbox(label="Generated Caption")
535
  run_button = gr.Button("Make My Caption!")
536
 
 
573
 
574
  caption_type.change(update_style_options, inputs=[caption_type], outputs=[advanced_options])
575
 
576
+ def process_and_handle_errors(input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition_style, lighting_aspect, special_technique, color_effect):
577
+ try:
578
+ result = stream_chat(input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition_style, lighting_aspect, special_technique, color_effect)
579
+ return gr.update(visible=False), result
580
+ except Exception as e:
581
+ return gr.update(visible=True, value=f"Error: {str(e)}"), ""
582
+
583
+ run_button.click(
584
+ fn=process_and_handle_errors,
585
+ inputs=[input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition_style, lighting_aspect, special_technique, color_effect],
586
+ outputs=[error_message, output_caption]
587
+ )
588
 
589
 
590
  if __name__ == "__main__":