litav commited on
Commit
b08ee34
verified
1 Parent(s): 135696c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -35
app.py CHANGED
@@ -1,35 +1,15 @@
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(2) # 砖讬谞讜讬 讛讝诪谉 诇驻讬 讛爪讜专讱
12
- label, confidence = model.predict(image)
13
- result = "AI image" if label == 1 else "Real image"
14
- return result, f"Confidence: {confidence:.2f}%"
15
-
16
- # Define the Gradio interface
17
- with gr.Blocks() as demo:
18
- image_input = gr.Image(type="pil", label="Upload an image")
19
- animation = gr.Video("https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4", visible=False)
20
- output_label = gr.Textbox(label="Classification Result", interactive=False)
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
- # 注讚讻讜谉 注诇 讛讗讬专讜注讬诐
31
- image_input.change(show_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
32
- image_input.submit(hide_animation, inputs=image_input, outputs=[output_label, output_confidence])
33
-
34
- # Launch the Gradio interface
35
- demo.launch()
 
1
+ import requests
2
+
3
+ def check_video_url(video_url):
4
+ try:
5
+ response = requests.head(video_url) # 诪讘爪注 讘拽砖转 HEAD 诇讘讚讜拽 讗转 讛-URL
6
+ if response.status_code == 200:
7
+ print("The video URL is valid and accessible.")
8
+ else:
9
+ print(f"Received status code: {response.status_code}. The video may not be accessible.")
10
+ except requests.exceptions.RequestException as e:
11
+ print(f"An error occurred: {e}")
12
+
13
+ # 拽讬砖讜专 诇住专讟讜谉 诇讘讚讬拽讛
14
+ video_url = "https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4"
15
+ check_video_url(video_url)