Tophness2022 commited on
Commit
0b47aad
·
1 Parent(s): 383f8a4

pre-merge for exif support

Browse files
Files changed (1) hide show
  1. gradio_server.py +20 -5
gradio_server.py CHANGED
@@ -1164,6 +1164,24 @@ def expand_slist(slist, num_inference_steps ):
1164
  pos += inc
1165
  return new_slist
1166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1167
  def generate_video(
1168
  task_id,
1169
  prompt,
@@ -1214,9 +1232,6 @@ def generate_video(
1214
  print(f"Model loaded")
1215
  reload_needed= False
1216
 
1217
- import numpy as np
1218
- import tempfile
1219
-
1220
  if wan_model == None:
1221
  raise gr.Error("Unable to generate a Video while a new configuration is being applied.")
1222
  if attention_mode == "auto":
@@ -1413,8 +1428,8 @@ def generate_video(
1413
  if image2video:
1414
  samples = wan_model.generate(
1415
  prompt,
1416
- image_to_continue.convert('RGB'),
1417
- image_to_end.convert('RGB') if image_to_end != None else None,
1418
  frame_num=(video_length // 4)* 4 + 1,
1419
  max_area=MAX_AREA_CONFIGS[resolution],
1420
  shift=flow_shift,
 
1164
  pos += inc
1165
  return new_slist
1166
 
1167
+ def convert_image(image):
1168
+ from PIL import ExifTags
1169
+
1170
+ image = image.convert('RGB')
1171
+ for orientation in ExifTags.TAGS.keys():
1172
+ if ExifTags.TAGS[orientation]=='Orientation':
1173
+ break
1174
+ exif = image.getexif()
1175
+ if not orientation in exif:
1176
+ return image
1177
+ if exif[orientation] == 3:
1178
+ image=image.rotate(180, expand=True)
1179
+ elif exif[orientation] == 6:
1180
+ image=image.rotate(270, expand=True)
1181
+ elif exif[orientation] == 8:
1182
+ image=image.rotate(90, expand=True)
1183
+ return image
1184
+
1185
  def generate_video(
1186
  task_id,
1187
  prompt,
 
1232
  print(f"Model loaded")
1233
  reload_needed= False
1234
 
 
 
 
1235
  if wan_model == None:
1236
  raise gr.Error("Unable to generate a Video while a new configuration is being applied.")
1237
  if attention_mode == "auto":
 
1428
  if image2video:
1429
  samples = wan_model.generate(
1430
  prompt,
1431
+ convert_image(image_to_continue),
1432
+ convert_image(image_to_end) if image_to_end != None else None,
1433
  frame_num=(video_length // 4)* 4 + 1,
1434
  max_area=MAX_AREA_CONFIGS[resolution],
1435
  shift=flow_shift,