Chris Addis commited on
Commit
11b5f4d
·
1 Parent(s): a1d918e
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -74,18 +74,25 @@ def get_base_filename(filepath):
74
  def create_demo():
75
  # --- Reintroduce CSS ---
76
  custom_css = """
77
- /* Target the img element *inside* the component with ID 'current-image-display' */
78
- #current-image-display img {
79
- object-fit: contain !important; /* Scale down while maintaining aspect ratio */
80
- width: 100% !important; /* Make image width fill the container */
81
- height: 100% !important; /* Make image height fill the container */
82
- }
83
- /* Optional: Ensure the container itself respects the height */
84
- #current-image-display {
85
- height: 600px; /* Match the height set in gr.Image */
86
- /* width: 100%; /* Usually takes column width */
87
- /* overflow: hidden; /* Can prevent potential overflow */
88
- }
 
 
 
 
 
 
 
89
  """
90
  # --- Pass css to gr.Blocks ---
91
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
 
74
  def create_demo():
75
  # --- Reintroduce CSS ---
76
  custom_css = """
77
+ /* Container for the image component (#current-image-display is the elem_id of gr.Image) */
78
+ #current-image-display {
79
+ height: 600px; /* Define container height */
80
+ width: 100%; /* Define container width (takes column width) */
81
+ display: flex; /* Use flexbox for alignment */
82
+ justify-content: center; /* Center content horizontally */
83
+ align-items: center; /* Center content vertically */
84
+ overflow: hidden; /* Hide any potential overflow from container */
85
+ }
86
+
87
+ /* The actual <img> element inside the container */
88
+ #current-image-display img {
89
+ object-fit: contain; /* Scale keeping aspect ratio, within bounds */
90
+ max-width: 100%; /* Prevent image exceeding container width */
91
+ max-height: 100%; /* Prevent image exceeding container height */
92
+ width: auto; /* Use natural width unless constrained by max-width */
93
+ height: auto; /* Use natural height unless constrained by max-height */
94
+ display: block; /* Ensure image behaves predictably in flex */
95
+ }
96
  """
97
  # --- Pass css to gr.Blocks ---
98
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo: