bgamazay commited on
Commit
89b17b0
·
verified ·
1 Parent(s): da5a01c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -32,14 +32,14 @@ def main():
32
 
33
  # Dropdown for selecting a model
34
  st.sidebar.write("### Instructions:")
35
- st.sidebar.write("1. Select a model below")
36
  model_options = data_df["model"].unique().tolist() # Get model options
37
  selected_model = st.sidebar.selectbox(
38
  "Scored Models", model_options, help="Start typing to search for a model"
39
  ) # Searchable dropdown
40
 
41
  # Add step 2 instructions and move the Download button
42
- st.sidebar.write("2. Download the label")
43
 
44
  # Filter the data for the selected model
45
  model_data = data_df[data_df["model"] == selected_model].iloc[0]
@@ -81,16 +81,19 @@ def main():
81
  )
82
 
83
  # Step 3 instructions
84
- st.sidebar.write("3. Share your label in technical reports, announcements, etc.")
85
 
86
  def create_label(background_image, model_data):
87
  """
88
  Create the label image by adding text from model_data to the background image.
 
89
  """
90
- scale_factor = 2 # Render at 2x resolution for better text clarity
91
- high_res_size = (800 * scale_factor, 600 * scale_factor)
 
 
92
 
93
- # Resize background to high resolution
94
  high_res_image = background_image.resize(high_res_size, Image.Resampling.LANCZOS)
95
  draw = ImageDraw.Draw(high_res_image)
96
 
@@ -129,8 +132,8 @@ def create_label(background_image, model_data):
129
  energy_text_width = bbox[2] - bbox[0]
130
  draw.text((energy_x - energy_text_width // 2, energy_y), energy_text, font=energy_font, fill="black")
131
 
132
- # Downscale to the target resolution
133
- final_image = high_res_image.resize((800, 600), Image.Resampling.LANCZOS)
134
  return final_image
135
 
136
  if __name__ == "__main__":
 
32
 
33
  # Dropdown for selecting a model
34
  st.sidebar.write("### Instructions:")
35
+ st.sidebar.write("# 1. Select a model below")
36
  model_options = data_df["model"].unique().tolist() # Get model options
37
  selected_model = st.sidebar.selectbox(
38
  "Scored Models", model_options, help="Start typing to search for a model"
39
  ) # Searchable dropdown
40
 
41
  # Add step 2 instructions and move the Download button
42
+ st.sidebar.write("# 2. Download the label")
43
 
44
  # Filter the data for the selected model
45
  model_data = data_df[data_df["model"] == selected_model].iloc[0]
 
81
  )
82
 
83
  # Step 3 instructions
84
+ st.sidebar.write("# 3. Share your label in technical reports, announcements, etc.")
85
 
86
  def create_label(background_image, model_data):
87
  """
88
  Create the label image by adding text from model_data to the background image.
89
+ Render at high resolution and scale down for sharper output.
90
  """
91
+ # Scale factor for high resolution rendering
92
+ scale_factor = 2
93
+ original_size = background_image.size
94
+ high_res_size = (original_size[0] * scale_factor, original_size[1] * scale_factor)
95
 
96
+ # Resize background proportionally for high resolution
97
  high_res_image = background_image.resize(high_res_size, Image.Resampling.LANCZOS)
98
  draw = ImageDraw.Draw(high_res_image)
99
 
 
132
  energy_text_width = bbox[2] - bbox[0]
133
  draw.text((energy_x - energy_text_width // 2, energy_y), energy_text, font=energy_font, fill="black")
134
 
135
+ # Downscale to original size
136
+ final_image = high_res_image.resize(original_size, Image.Resampling.LANCZOS)
137
  return final_image
138
 
139
  if __name__ == "__main__":