litav commited on
Commit
aabb767
verified
1 Parent(s): 537ad5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -7,9 +7,9 @@ import time # 专拽 诇爪讜专讱 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
7
  model = CustomModel()
8
 
9
  def predict(image: Image.Image):
10
- # 讝诪谉 讞讬砖讜讘 诪讜讚诇 (诪讚讜诪讛)
11
- time.sleep(5) # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
12
-
13
  # 讛驻注诇转 讛诪讜讚诇 讻讚讬 诇住讜讜讙 讗转 讛转诪讜谞讛
14
  label, confidence = model.predict(image)
15
  result = "AI image" if label == 1 else "Real image"
@@ -18,7 +18,7 @@ def predict(image: Image.Image):
18
 
19
  def loading_animation(image):
20
  # 诪爪讬讙 讜讬讚讗讜 注讚 砖转讜爪讗转 讛诪讜讚诇 诪转拽讘诇转
21
- return gr.Video.update(visible=True), gr.Textbox.update(visible=False), gr.Textbox.update(visible=False)
22
 
23
  def show_results(image):
24
  # 诪驻注讬诇 讗转 讛诪讜讚诇 讜诪讞讝讬专 讗转 讛转讜爪讗讜转
@@ -35,12 +35,12 @@ with gr.Blocks() as demo:
35
  animation = gr.Video("https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4", visible=False)
36
 
37
  # 转讜爪讗讜转
38
- output_label = gr.Textbox(label="Classification Result", visible=False)
39
- output_confidence = gr.Textbox(label="Confidence", visible=False)
40
 
41
  # 讗讬专讜注讬诐
42
  image_input.change(loading_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
43
- image_input.change(show_results, inputs=image_input, outputs=[animation, output_label, output_confidence])
44
 
45
  # 讛砖拽转 讛诪诪砖拽
46
  demo.launch()
 
7
  model = CustomModel()
8
 
9
  def predict(image: Image.Image):
10
+ # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
11
+ time.sleep(3)
12
+
13
  # 讛驻注诇转 讛诪讜讚诇 讻讚讬 诇住讜讜讙 讗转 讛转诪讜谞讛
14
  label, confidence = model.predict(image)
15
  result = "AI image" if label == 1 else "Real image"
 
18
 
19
  def loading_animation(image):
20
  # 诪爪讬讙 讜讬讚讗讜 注讚 砖转讜爪讗转 讛诪讜讚诇 诪转拽讘诇转
21
+ return gr.Video.update(visible=True), "", ""
22
 
23
  def show_results(image):
24
  # 诪驻注讬诇 讗转 讛诪讜讚诇 讜诪讞讝讬专 讗转 讛转讜爪讗讜转
 
35
  animation = gr.Video("https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4", visible=False)
36
 
37
  # 转讜爪讗讜转
38
+ output_label = gr.Textbox(label="Classification Result", interactive=False, visible=False)
39
+ output_confidence = gr.Textbox(label="Confidence", interactive=False, visible=False)
40
 
41
  # 讗讬专讜注讬诐
42
  image_input.change(loading_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
43
+ image_input.submit(show_results, inputs=image_input, outputs=[animation, output_label, output_confidence])
44
 
45
  # 讛砖拽转 讛诪诪砖拽
46
  demo.launch()