litav commited on
Commit
8c24779
verified
1 Parent(s): bdaa99a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -7,8 +7,8 @@ import time
7
  model = CustomModel()
8
 
9
  def predict(image: Image.Image):
10
- # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚 (诇诪砖诇 5 砖谞讬讜转)
11
- time.sleep(5) # 讗驻砖专 诇砖谞讜转 讗转 讛讝诪谉 诇驻讬 讛爪讜专讱
12
  label, confidence = model.predict(image)
13
  result = "AI image" if label == 1 else "Real image"
14
  return result, f"Confidence: {confidence:.2f}%"
@@ -21,14 +21,16 @@ with gr.Blocks() as demo:
21
  output_confidence = gr.Textbox(label="Confidence", interactive=False)
22
 
23
  def show_animation(image):
24
- return animation.update(visible=True), "", "" # 诇讛爪讬讙 讗转 讛讗谞讬诪爪讬讛
 
25
 
26
  def hide_animation(image):
27
  result, confidence = predict(image)
28
- return animation.update(visible=False), result, confidence # 诇讛住转讬专 讗转 讛讗谞讬诪爪讬讛
 
29
 
30
  image_input.change(show_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
31
- image_input.change(hide_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
32
 
33
  # Launch the Gradio interface
34
  demo.launch()
 
7
  model = CustomModel()
8
 
9
  def predict(image: Image.Image):
10
+ # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
11
+ time.sleep(2) # 砖讬谞讜讬 讛讝诪谉 诇驻讬 讛爪讜专讱
12
  label, confidence = model.predict(image)
13
  result = "AI image" if label == 1 else "Real image"
14
  return result, f"Confidence: {confidence:.2f}%"
 
21
  output_confidence = gr.Textbox(label="Confidence", interactive=False)
22
 
23
  def show_animation(image):
24
+ animation.visible = True
25
+ return animation, "", "" # 诇讛爪讬讙 讗转 讛讗谞讬诪爪讬讛
26
 
27
  def hide_animation(image):
28
  result, confidence = predict(image)
29
+ animation.visible = False # 诇讛住转讬专 讗转 讛讗谞讬诪爪讬讛
30
+ return result, confidence # 诇讛讞讝讬专 讗转 讛转讜爪讗讜转
31
 
32
  image_input.change(show_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
33
+ image_input.submit(hide_animation, inputs=image_input, outputs=[output_label, output_confidence])
34
 
35
  # Launch the Gradio interface
36
  demo.launch()