HarshitaSuri commited on
Commit
dada46f
·
verified ·
1 Parent(s): c7bde0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -5,11 +5,11 @@ import requests
5
  from serpapi import GoogleSearch
6
  import tempfile
7
 
8
- # Keys
9
- IMGBB_API_KEY = "YOUR_IMGBB_API_KEY"
10
- SERPAPI_API_KEY = "YOUR_SERPAPI_API_KEY"
11
 
12
- # Load deepfake detection model
13
  deepfake_detector = pipeline("image-classification", model="Wvolf/ViT_Deepfake_Detection")
14
 
15
  # Upload to ImgBB
@@ -27,7 +27,7 @@ def upload_image_to_imgbb(image, api_key):
27
  else:
28
  return None
29
 
30
- # Search online
31
  def search_deepfakes(query, api_key):
32
  params = {
33
  "q": query,
@@ -59,21 +59,25 @@ def detect_and_search(image):
59
  query = f"deepfake {image_url}"
60
  results = search_deepfakes(query, SERPAPI_API_KEY)
61
  if results:
62
- search_summary = f"\n🔎 Found {len(results)} visually similar images online.\nExample:\n- {results[0]['title']}\n- {results[0]['link']}"
 
 
 
 
63
  else:
64
  search_summary = "\n🔍 No similar deepfakes found online."
65
  else:
66
- search_summary = "\n⚠️ Error uploading image for search."
67
 
68
  return status + search_summary
69
 
70
- # Interface
71
  iface = gr.Interface(
72
  fn=detect_and_search,
73
- inputs=gr.Image(source="upload", tool="editor", type="pil", label="Upload or Capture Image"),
74
  outputs="text",
75
  title="Deepfake Confidence & Reverse Image Search",
76
- description="Upload or capture an image. This tool detects deepfakes and searches the internet to check if similar images already exist.",
77
  )
78
 
79
  if __name__ == "__main__":
 
5
  from serpapi import GoogleSearch
6
  import tempfile
7
 
8
+ # Replace with your actual API keys
9
+ IMGBB_API_KEY = "47cf5c6318ae2fc7d1ea3305189942c4"
10
+ SERPAPI_API_KEY = "d70b432deb7b0acfb440fada51e1446974913bb30cc753e78397752336b33db9"
11
 
12
+ # Load the deepfake detection model
13
  deepfake_detector = pipeline("image-classification", model="Wvolf/ViT_Deepfake_Detection")
14
 
15
  # Upload to ImgBB
 
27
  else:
28
  return None
29
 
30
+ # Search via SerpAPI
31
  def search_deepfakes(query, api_key):
32
  params = {
33
  "q": query,
 
59
  query = f"deepfake {image_url}"
60
  results = search_deepfakes(query, SERPAPI_API_KEY)
61
  if results:
62
+ first_result = results[0]
63
+ search_summary = (
64
+ f"\n🔎 Found {len(results)} visually similar images online.\n"
65
+ f"Example:\n- {first_result['title']}\n- {first_result['link']}"
66
+ )
67
  else:
68
  search_summary = "\n🔍 No similar deepfakes found online."
69
  else:
70
+ search_summary = "\n⚠️ Error uploading image for reverse search."
71
 
72
  return status + search_summary
73
 
74
+ # Gradio Interface
75
  iface = gr.Interface(
76
  fn=detect_and_search,
77
+ inputs=gr.Image(type="pil", label="Upload or Capture Image"),
78
  outputs="text",
79
  title="Deepfake Confidence & Reverse Image Search",
80
+ description="Upload or capture an image. This tool detects deepfakes and checks the internet for visually similar images using SerpAPI."
81
  )
82
 
83
  if __name__ == "__main__":