Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from models import
|
| 3 |
-
|
| 4 |
-
|
| 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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|