ash12321 commited on
Commit
c703015
Β·
verified Β·
1 Parent(s): 7f6aa38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -30
app.py CHANGED
@@ -1,35 +1,53 @@
1
  import gradio as gr
2
- from models import text_model, image_model, text_label_map
3
-
4
- def classify_text(text):
5
- res = text_model(text)[0]
6
- # Map numeric labels to user-readable text
7
- readable_label = text_label_map.get(res['label'], res['label'])
8
- return f"{readable_label} ({res['score']*100:.2f}% confidence)"
9
 
 
 
 
 
 
 
 
 
 
10
 
 
11
  def classify_image(image):
12
- res = image_model(image)[0]
13
- return f"{res['label']} ({res['score']*100:.2f}% confidence)"
14
-
15
- # --- Gradio UI ---
16
- with gr.Blocks(title="Authenticity Checker") as demo:
17
- gr.Markdown("## Real or Fake? (Text & Image Detector)")
18
- with gr.Row():
19
- with gr.Column():
20
- gr.Markdown("### Fake News Detection (Text)")
21
- text_input = gr.Textbox(lines=5, placeholder="Paste news text here...", label="Input Text")
22
- text_output = gr.Textbox(label="Result")
23
- text_button = gr.Button("Check Text")
24
- text_button.click(classify_text, inputs=text_input, outputs=text_output)
25
-
26
- with gr.Column():
27
- gr.Markdown("### Deepfake Detection (Image)")
28
- image_input = gr.Image(type="pil", label="Upload Image")
29
- image_output = gr.Textbox(label="Result")
30
- image_button = gr.Button("Check Image")
31
- image_button.click(classify_image, inputs=image_input, outputs=image_output)
32
-
33
- if __name__ == "__main__":
34
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
35
 
 
1
  import gradio as gr
2
+ from models import text_model_1, text_label_map_1, text_model_2, text_label_map_2
3
+ from models import image_model_1, image_label_map_1, image_model_2, image_label_map_2
4
+ from models import video_model
 
 
 
 
5
 
6
+ # Text classification function (combines two text models)
7
+ def classify_text(input_text):
8
+ results = []
9
+ for model, label_map in [(text_model_1, text_label_map_1), (text_model_2, text_label_map_2)]:
10
+ res = model(input_text)[0]
11
+ label = label_map.get(res['label'], res['label'])
12
+ score = res['score'] * 100
13
+ results.append(f"{label} ({score:.2f}%)")
14
+ return "\n".join(results)
15
 
16
+ # Image classification function (combines two image models)
17
  def classify_image(image):
18
+ results = []
19
+ for model, label_map in [(image_model_1, image_label_map_1), (image_model_2, image_label_map_2)]:
20
+ res = model(image)[0]
21
+ label = label_map.get(res['label'], res['label'])
22
+ score = res['score'] * 100
23
+ results.append(f"{label} ({score:.2f}%)")
24
+ return "\n".join(results)
25
+
26
+ # Video classification placeholder
27
+ def classify_video(video_file):
28
+ return video_model(video_file)
29
+
30
+ # Gradio UI
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("## Multi-Modal AI Detection Tool")
33
+
34
+ with gr.Tab("Text Detection"):
35
+ text_input = gr.Textbox(label="Enter text")
36
+ text_output = gr.Textbox(label="Predictions")
37
+ text_btn = gr.Button("Classify Text")
38
+ text_btn.click(classify_text, inputs=text_input, outputs=text_output)
39
+
40
+ with gr.Tab("Image Detection"):
41
+ image_input = gr.Image(type="pil")
42
+ image_output = gr.Textbox(label="Predictions")
43
+ image_btn = gr.Button("Classify Image")
44
+ image_btn.click(classify_image, inputs=image_input, outputs=image_output)
45
+
46
+ with gr.Tab("Video Detection"):
47
+ video_input = gr.File(label="Upload video")
48
+ video_output = gr.Textbox(label="Prediction")
49
+ video_btn = gr.Button("Classify Video")
50
+ video_btn.click(classify_video, inputs=video_input, outputs=video_output)
51
+
52
+ demo.launch()
53