benjaminStreltzin commited on
Commit
a64f4ed
·
verified ·
1 Parent(s): dbc65b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -12
app.py CHANGED
@@ -6,18 +6,40 @@ from vit_model_test import CustomModel
6
  model = CustomModel()
7
 
8
  def predict(image: Image.Image):
9
- # Get predictions from the model
10
- label, confidence = model.predict(image)
11
-
12
- # Determine the result based on the label
13
- if label == 1:
14
- result = "AI image"
15
- else:
16
- result = "Real image"
17
-
18
- return result, f"Confidence: {confidence:.2f}%"
19
 
20
- # Define the Gradio interface with updated API
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  demo = gr.Interface(
22
  fn=predict,
23
  inputs=gr.Image(type="pil"),
@@ -26,6 +48,8 @@ demo = gr.Interface(
26
  description="Upload an image to classify it using the Vision Transformer model."
27
  )
28
 
29
- # Launch the Gradio interface
 
30
 
 
31
  demo.launch()
 
6
  model = CustomModel()
7
 
8
  def predict(image: Image.Image):
9
+ try:
10
+ label, confidence = model.predict(image)
11
+ result = "AI image" if label == 1 else "Real image"
12
+ return result, f"Confidence: {confidence:.2f}%"
13
+ except Exception as e:
14
+ return "Error in prediction", str(e)
 
 
 
 
15
 
16
+ # Custom HTML and CSS to replace the logo with a video
17
+ custom_html = """
18
+ <style>
19
+ /* Hide the default logo */
20
+ .gradio-logo {
21
+ display: none;
22
+ }
23
+ /* Center the video container */
24
+ .loading-container {
25
+ text-align: center;
26
+ margin-top: 20px;
27
+ }
28
+ .loading-container video {
29
+ width: 320px; /* Adjust video size */
30
+ height: auto; /* Maintain aspect ratio */
31
+ }
32
+ </style>
33
+ <div class="loading-container">
34
+ <video autoplay muted loop>
35
+ <source src="load_screen.mp4" type="video/mp4">
36
+ Your browser does not support the video tag.
37
+ </video>
38
+ <div>Processing, please wait...</div>
39
+ </div>
40
+ """
41
+
42
+ # Define the Gradio interface
43
  demo = gr.Interface(
44
  fn=predict,
45
  inputs=gr.Image(type="pil"),
 
48
  description="Upload an image to classify it using the Vision Transformer model."
49
  )
50
 
51
+ # Inject the custom HTML to show the video instead of the logo
52
+ demo.load(custom_html)
53
 
54
+ # Launch the Gradio interface
55
  demo.launch()