Fabrice-TIERCELIN commited on
Commit
2bf0610
1 Parent(s): f5bc7f0

Do not return the original

Browse files
Files changed (1) hide show
  1. app.py +6 -38
app.py CHANGED
@@ -81,10 +81,7 @@ def check(input_image):
81
  if input_image is None:
82
  raise gr.Error("Please provide an image to restore.")
83
 
84
- def reset_feedback():
85
- return 3, ''
86
-
87
- @spaces.GPU(duration=480)
88
  def stage1_process(input_image, gamma_correction):
89
  print('stage1_process ==>>')
90
  if torch.cuda.device_count() == 0:
@@ -106,22 +103,6 @@ def stage1_process(input_image, gamma_correction):
106
  print('<<== stage1_process')
107
  return LQ, gr.update(visible = True)
108
 
109
- @spaces.GPU(duration=540)
110
- def llave_process(input_image, temperature, top_p, qs=None):
111
- print('llave_process ==>>')
112
- if torch.cuda.device_count() == 0:
113
- gr.Warning('Set this space to GPU config to make it work.')
114
- return 'Set this space to GPU config to make it work.'
115
- torch.cuda.set_device(LLaVA_device)
116
- if use_llava:
117
- LQ = HWC3(input_image)
118
- LQ = Image.fromarray(LQ.astype('uint8'))
119
- captions = llava_agent.gen_image_caption([LQ], temperature=temperature, top_p=top_p, qs=qs)
120
- else:
121
- captions = ['LLaVA is not available. Please add text manually.']
122
- print('<<== llave_process')
123
- return captions[0]
124
-
125
  def stage2_process(
126
  noisy_image,
127
  rotation,
@@ -413,7 +394,7 @@ def restore(
413
  print(information)
414
 
415
  # Only one image can be shown in the slider
416
- return [input_image] + [results[0]], gr.update(format = output_format, value = [input_image] + results), gr.update(value = information, visible = True)
417
 
418
  def load_and_reset(param_setting):
419
  print('load_and_reset ==>>')
@@ -456,22 +437,9 @@ def log_information(result_gallery):
456
  for i, result in enumerate(result_gallery):
457
  print(result[0])
458
 
459
- def on_select_result(result_gallery, evt: gr.SelectData):
460
  print('on_select_result')
461
- return [result_gallery[0][0], result_gallery[evt.index][0]]
462
-
463
- def submit_feedback(event_id, fb_score, fb_text):
464
- if args.log_history:
465
- with open(f'./history/{event_id[:5]}/{event_id[5:]}/logs.txt', 'r') as f:
466
- event_dict = eval(f.read())
467
- f.close()
468
- event_dict['feedback'] = {'score': fb_score, 'text': fb_text}
469
- with open(f'./history/{event_id[:5]}/{event_id[5:]}/logs.txt', 'w') as f:
470
- f.write(str(event_dict))
471
- f.close()
472
- return 'Submit successfully, thank you for your comments!'
473
- else:
474
- return 'Submit failed, the server is not set to log history.'
475
 
476
  title_html = """
477
  <h1><center>SUPIR</center></h1>
@@ -503,7 +471,7 @@ The service is a research preview intended for non-commercial use only, subject
503
  """
504
 
505
  # Gradio interface
506
- with gr.Blocks(title="SUPIR") as interface:
507
  if torch.cuda.device_count() == 0:
508
  with gr.Row():
509
  gr.HTML("""
@@ -760,7 +728,7 @@ with gr.Blocks(title="SUPIR") as interface:
760
  result_gallery
761
  ], outputs = [], queue = False, show_progress = False)
762
 
763
- result_gallery.select(on_select_result, result_gallery, result_slider)
764
 
765
  restart_button.click(fn = load_and_reset, inputs = [
766
  param_setting
 
81
  if input_image is None:
82
  raise gr.Error("Please provide an image to restore.")
83
 
84
+ @spaces.GPU(duration=420)
 
 
 
85
  def stage1_process(input_image, gamma_correction):
86
  print('stage1_process ==>>')
87
  if torch.cuda.device_count() == 0:
 
103
  print('<<== stage1_process')
104
  return LQ, gr.update(visible = True)
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  def stage2_process(
107
  noisy_image,
108
  rotation,
 
394
  print(information)
395
 
396
  # Only one image can be shown in the slider
397
+ return [results[0]], gr.update(format = output_format, value = results), gr.update(value = information, visible = True)
398
 
399
  def load_and_reset(param_setting):
400
  print('load_and_reset ==>>')
 
437
  for i, result in enumerate(result_gallery):
438
  print(result[0])
439
 
440
+ def on_select_result(result_slider, result_gallery, evt: gr.SelectData):
441
  print('on_select_result')
442
+ return [result_slider[0], result_gallery[evt.index][0]]
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
  title_html = """
445
  <h1><center>SUPIR</center></h1>
 
471
  """
472
 
473
  # Gradio interface
474
+ with gr.Blocks() as interface:
475
  if torch.cuda.device_count() == 0:
476
  with gr.Row():
477
  gr.HTML("""
 
728
  result_gallery
729
  ], outputs = [], queue = False, show_progress = False)
730
 
731
+ result_gallery.select(on_select_result, [result_slider, result_gallery], result_slider)
732
 
733
  restart_button.click(fn = load_and_reset, inputs = [
734
  param_setting