litav commited on
Commit
a933cfb
verified
1 Parent(s): 802a34b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -45
app.py CHANGED
@@ -1,46 +1,6 @@
1
- import gradio as gr
2
- from PIL import Image
3
- from vit_model_test import CustomModel
4
- import time # 专拽 诇爪讜专讱 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
5
 
6
- # Initialize the model
7
- model = CustomModel()
8
-
9
- def predict(image: Image.Image):
10
- # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
11
- time.sleep(1)
12
-
13
- # 讛驻注诇转 讛诪讜讚诇 讻讚讬 诇住讜讜讙 讗转 讛转诪讜谞讛
14
- label, confidence = model.predict(image)
15
- result = "AI image" if label == 1 else "Real image"
16
-
17
- return result, f"Confidence: {confidence:.2f}%"
18
-
19
- def loading_animation(image):
20
- # 诪爪讬讙 讜讬讚讗讜 注讚 砖转讜爪讗转 讛诪讜讚诇 诪转拽讘诇转
21
- return gr.Video.update(visible=True), "", ""
22
-
23
- def show_results(image):
24
- # 诪驻注讬诇 讗转 讛诪讜讚诇 讜诪讞讝讬专 讗转 讛转讜爪讗讜转
25
- result, confidence = predict(image)
26
- return gr.Video.update(visible=True), result, confidence
27
-
28
- # 讬爪讬专转 诪诪砖拽 Gradio
29
- with gr.Blocks() as demo:
30
- with gr.Row():
31
- # 拽诇讟 转诪讜谞讛
32
- image_input = gr.Image(type="pil", label="Upload an image")
33
-
34
- # 讜讬讚讗讜 讗谞讬诪爪讬讛 (诪讜住转专 讘讛转讞诇讛)
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.change(show_results, inputs=image_input, outputs=[animation, output_label, output_confidence])
44
-
45
- # 讛砖拽转 讛诪诪砖拽
46
- demo.launch()
 
1
+ import os
 
 
 
2
 
3
+ if os.path.exists("https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4"):
4
+ print("The video file exists.")
5
+ else:
6
+ print("The video file does not exist.")