Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
from transformers import pipeline
|
| 4 |
-
import fitz # PyMuPDF for PDF extraction
|
| 5 |
|
| 6 |
# -------------------------------
|
| 7 |
# Load Models
|
| 8 |
# -------------------------------
|
| 9 |
-
# Text detector (public)
|
| 10 |
text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
|
| 11 |
-
|
| 12 |
-
# Image classifier (public baseline, since AI-specific detectors are often gated)
|
| 13 |
image_analyzer = pipeline("image-classification", model="microsoft/resnet-50")
|
| 14 |
-
|
| 15 |
-
# Whisper tiny for audio โ text transcription
|
| 16 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
|
| 17 |
|
| 18 |
# -------------------------------
|
| 19 |
-
#
|
| 20 |
# -------------------------------
|
| 21 |
-
|
| 22 |
@spaces.GPU
|
| 23 |
def oracle_text(user_text: str):
|
| 24 |
-
if not user_text
|
| 25 |
-
return "โ ๏ธ Please
|
| 26 |
result = text_detector(user_text)
|
| 27 |
label = result[0]['label']
|
| 28 |
score = round(result[0]['score'] * 100, 2)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
@spaces.GPU
|
| 35 |
def oracle_image(user_img):
|
|
@@ -38,7 +33,7 @@ def oracle_image(user_img):
|
|
| 38 |
result = image_analyzer(user_img)
|
| 39 |
label = result[0]['label']
|
| 40 |
score = round(result[0]['score'] * 100, 2)
|
| 41 |
-
return f"
|
| 42 |
|
| 43 |
@spaces.GPU
|
| 44 |
def oracle_audio(audio_file):
|
|
@@ -48,10 +43,11 @@ def oracle_audio(audio_file):
|
|
| 48 |
result = text_detector(transcript)
|
| 49 |
label = result[0]['label']
|
| 50 |
score = round(result[0]['score'] * 100, 2)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
return verdict
|
| 56 |
|
| 57 |
@spaces.GPU
|
|
@@ -59,101 +55,93 @@ def oracle_pdf(pdf_file):
|
|
| 59 |
if pdf_file is None:
|
| 60 |
return "โ ๏ธ Please upload a PDF."
|
| 61 |
doc = fitz.open(pdf_file)
|
| 62 |
-
text = ""
|
| 63 |
-
for page in doc:
|
| 64 |
-
text += page.get_text()
|
| 65 |
if not text.strip():
|
| 66 |
-
return "โ ๏ธ
|
| 67 |
-
|
| 68 |
-
result = text_detector(text[:800]) # limit chars for speed
|
| 69 |
label = result[0]['label']
|
| 70 |
score = round(result[0]['score'] * 100, 2)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
# -------------------------------
|
| 77 |
# Gradio Immersive UI
|
| 78 |
# -------------------------------
|
| 79 |
with gr.Blocks(css="""
|
| 80 |
body {
|
| 81 |
-
background: linear-gradient(135deg, #ff9a9e, #fad0c4, #
|
| 82 |
font-family: 'Trebuchet MS', sans-serif;
|
| 83 |
-
color:
|
| 84 |
}
|
| 85 |
#title {
|
| 86 |
text-align: center;
|
| 87 |
-
font-size:
|
| 88 |
color: #FFD700;
|
| 89 |
padding: 20px;
|
| 90 |
-
text-shadow:
|
| 91 |
}
|
| 92 |
#subtitle {
|
| 93 |
text-align: center;
|
| 94 |
-
font-size: 1.
|
| 95 |
-
color: #
|
| 96 |
-
margin-bottom:
|
| 97 |
}
|
| 98 |
.result-box {
|
| 99 |
-
background: rgba(
|
| 100 |
border-radius: 15px;
|
| 101 |
padding: 20px;
|
| 102 |
-
font-size: 1.
|
| 103 |
-
|
| 104 |
-
|
| 105 |
box-shadow: 0px 0px 15px #FFD700;
|
| 106 |
}
|
| 107 |
""") as demo:
|
| 108 |
|
| 109 |
gr.HTML("<div id='title'>๐ฎ Oracle of Truth ๐ฎ</div>")
|
| 110 |
-
gr.HTML("<div id='subtitle'>
|
| 111 |
-
|
| 112 |
-
gr.Markdown("""
|
| 113 |
-
Welcome, seeker ๐
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
- ๐ผ๏ธ Upload images in the **Image Prophecy** panel.
|
| 121 |
-
- ๐ Speak into the **Voice Revelation** panel.
|
| 122 |
-
- ๐ Offer a **PDF** to see if it was written by human or AI.
|
| 123 |
|
| 124 |
-
|
| 125 |
""")
|
| 126 |
|
| 127 |
with gr.Tab("๐ Text Divination"):
|
| 128 |
-
txt_in = gr.Textbox(lines=
|
| 129 |
btn_txt = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 130 |
txt_out = gr.Markdown(elem_classes="result-box")
|
| 131 |
btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
|
| 132 |
|
| 133 |
gr.Examples(
|
| 134 |
examples=[
|
| 135 |
-
["Once upon a time in a galaxy
|
| 136 |
-
["
|
| 137 |
-
["
|
| 138 |
-
["This
|
| 139 |
],
|
| 140 |
inputs=txt_in
|
| 141 |
)
|
| 142 |
|
| 143 |
with gr.Tab("๐ผ๏ธ Image Prophecy"):
|
| 144 |
-
img_in = gr.Image(type="filepath", label="Upload
|
| 145 |
btn_img = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 146 |
img_out = gr.Markdown(elem_classes="result-box")
|
| 147 |
btn_img.click(oracle_image, inputs=img_in, outputs=img_out)
|
| 148 |
|
| 149 |
with gr.Tab("๐ Voice Revelation"):
|
| 150 |
-
aud_in = gr.Audio(sources=["microphone"], type="filepath", label="Speak
|
| 151 |
btn_aud = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 152 |
aud_out = gr.Markdown(elem_classes="result-box")
|
| 153 |
btn_aud.click(oracle_audio, inputs=aud_in, outputs=aud_out)
|
| 154 |
|
| 155 |
with gr.Tab("๐ PDF Prophecy"):
|
| 156 |
-
pdf_in = gr.File(label="Upload PDF
|
| 157 |
btn_pdf = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 158 |
pdf_out = gr.Markdown(elem_classes="result-box")
|
| 159 |
btn_pdf.click(oracle_pdf, inputs=pdf_in, outputs=pdf_out)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
from transformers import pipeline
|
| 4 |
+
import fitz # PyMuPDF for PDF text extraction
|
| 5 |
|
| 6 |
# -------------------------------
|
| 7 |
# Load Models
|
| 8 |
# -------------------------------
|
|
|
|
| 9 |
text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
|
|
|
|
|
|
|
| 10 |
image_analyzer = pipeline("image-classification", model="microsoft/resnet-50")
|
|
|
|
|
|
|
| 11 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
|
| 12 |
|
| 13 |
# -------------------------------
|
| 14 |
+
# Functions
|
| 15 |
# -------------------------------
|
|
|
|
| 16 |
@spaces.GPU
|
| 17 |
def oracle_text(user_text: str):
|
| 18 |
+
if not user_text.strip():
|
| 19 |
+
return "โ ๏ธ Please enter some text."
|
| 20 |
result = text_detector(user_text)
|
| 21 |
label = result[0]['label']
|
| 22 |
score = round(result[0]['score'] * 100, 2)
|
| 23 |
+
return (
|
| 24 |
+
f"๐ **Prophecy:** {score}% chance this was conjured by AI ๐คโจ"
|
| 25 |
+
if label.lower() == "fake"
|
| 26 |
+
else f"โ๏ธ **Prophecy:** {score}% chance this was crafted by a Human ๐งโ๐ป"
|
| 27 |
+
)
|
| 28 |
|
| 29 |
@spaces.GPU
|
| 30 |
def oracle_image(user_img):
|
|
|
|
| 33 |
result = image_analyzer(user_img)
|
| 34 |
label = result[0]['label']
|
| 35 |
score = round(result[0]['score'] * 100, 2)
|
| 36 |
+
return f"๐ผ๏ธ Oracleโs Sight: {score}% resemblance to *{label}*\n*(Image prophecy experimental ๐)*"
|
| 37 |
|
| 38 |
@spaces.GPU
|
| 39 |
def oracle_audio(audio_file):
|
|
|
|
| 43 |
result = text_detector(transcript)
|
| 44 |
label = result[0]['label']
|
| 45 |
score = round(result[0]['score'] * 100, 2)
|
| 46 |
+
verdict = (
|
| 47 |
+
f"๐ Transcript: *{transcript}*\n\n๐ Prophecy: {score}% AIโgenerated."
|
| 48 |
+
if label.lower() == "fake"
|
| 49 |
+
else f"๐ Transcript: *{transcript}*\n\nโ๏ธ Prophecy: {score}% Humanโwritten."
|
| 50 |
+
)
|
| 51 |
return verdict
|
| 52 |
|
| 53 |
@spaces.GPU
|
|
|
|
| 55 |
if pdf_file is None:
|
| 56 |
return "โ ๏ธ Please upload a PDF."
|
| 57 |
doc = fitz.open(pdf_file)
|
| 58 |
+
text = "".join(page.get_text() for page in doc)
|
|
|
|
|
|
|
| 59 |
if not text.strip():
|
| 60 |
+
return "โ ๏ธ No readable text found in PDF!"
|
| 61 |
+
result = text_detector(text[:800])
|
|
|
|
| 62 |
label = result[0]['label']
|
| 63 |
score = round(result[0]['score'] * 100, 2)
|
| 64 |
+
return (
|
| 65 |
+
f"๐ PDF Prophecy: {score}% AIโgenerated."
|
| 66 |
+
if label.lower() == "fake"
|
| 67 |
+
else f"๐ PDF Prophecy: {score}% Humanโauthored."
|
| 68 |
+
)
|
| 69 |
|
| 70 |
# -------------------------------
|
| 71 |
# Gradio Immersive UI
|
| 72 |
# -------------------------------
|
| 73 |
with gr.Blocks(css="""
|
| 74 |
body {
|
| 75 |
+
background: linear-gradient(135deg, #ff9a9e, #fad0c4, #a1c4fd, #c2e9fb);
|
| 76 |
font-family: 'Trebuchet MS', sans-serif;
|
| 77 |
+
color: #E0FFFF;
|
| 78 |
}
|
| 79 |
#title {
|
| 80 |
text-align: center;
|
| 81 |
+
font-size: 3em;
|
| 82 |
color: #FFD700;
|
| 83 |
padding: 20px;
|
| 84 |
+
text-shadow: 3px 3px 10px #000;
|
| 85 |
}
|
| 86 |
#subtitle {
|
| 87 |
text-align: center;
|
| 88 |
+
font-size: 1.4em;
|
| 89 |
+
color: #00FFFF;
|
| 90 |
+
margin-bottom: 30px;
|
| 91 |
}
|
| 92 |
.result-box {
|
| 93 |
+
background: rgba(0,0,0,0.6);
|
| 94 |
border-radius: 15px;
|
| 95 |
padding: 20px;
|
| 96 |
+
font-size: 1.4em;
|
| 97 |
+
margin-top: 15px;
|
| 98 |
+
color: #FFFFFF;
|
| 99 |
box-shadow: 0px 0px 15px #FFD700;
|
| 100 |
}
|
| 101 |
""") as demo:
|
| 102 |
|
| 103 |
gr.HTML("<div id='title'>๐ฎ Oracle of Truth ๐ฎ</div>")
|
| 104 |
+
gr.HTML("<div id='subtitle'>Multiโformat AI vs Human Divination โจ Text ยท Image ยท Voice ยท PDF</div>")
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
gr.Markdown("""
|
| 107 |
+
๐ **Welcome Seeker!**
|
| 108 |
|
| 109 |
+
The Oracle peers into your offering and reveals whether it was **AIโcrafted ๐ค** or **humanโmade ๐งโ๐ป**.
|
| 110 |
+
Choose one of the formats below โฌ๏ธ
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
๐ Paste text, upload an image, speak aloud, or offer a PDF.
|
| 113 |
""")
|
| 114 |
|
| 115 |
with gr.Tab("๐ Text Divination"):
|
| 116 |
+
txt_in = gr.Textbox(lines=8, label="๐ Enter your text", placeholder="Paste your essay, blog, or snippet hereโฆ")
|
| 117 |
btn_txt = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 118 |
txt_out = gr.Markdown(elem_classes="result-box")
|
| 119 |
btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
|
| 120 |
|
| 121 |
gr.Examples(
|
| 122 |
examples=[
|
| 123 |
+
["Once upon a time in a galaxy far away..."],
|
| 124 |
+
["Artificial Intelligence is revolutionizing health and education sectors across the globe."],
|
| 125 |
+
["LOL can't believe it's Monday ๐
"],
|
| 126 |
+
["This manuscript provides a comprehensive evaluation of machine translation systems."]
|
| 127 |
],
|
| 128 |
inputs=txt_in
|
| 129 |
)
|
| 130 |
|
| 131 |
with gr.Tab("๐ผ๏ธ Image Prophecy"):
|
| 132 |
+
img_in = gr.Image(type="filepath", label="๐ท Upload an image")
|
| 133 |
btn_img = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 134 |
img_out = gr.Markdown(elem_classes="result-box")
|
| 135 |
btn_img.click(oracle_image, inputs=img_in, outputs=img_out)
|
| 136 |
|
| 137 |
with gr.Tab("๐ Voice Revelation"):
|
| 138 |
+
aud_in = gr.Audio(sources=["microphone"], type="filepath", label="๐ค Speak to the Oracle")
|
| 139 |
btn_aud = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 140 |
aud_out = gr.Markdown(elem_classes="result-box")
|
| 141 |
btn_aud.click(oracle_audio, inputs=aud_in, outputs=aud_out)
|
| 142 |
|
| 143 |
with gr.Tab("๐ PDF Prophecy"):
|
| 144 |
+
pdf_in = gr.File(label="๐ Upload PDF file", file_types=[".pdf"])
|
| 145 |
btn_pdf = gr.Button("โจ Reveal Prophecy", variant="primary")
|
| 146 |
pdf_out = gr.Markdown(elem_classes="result-box")
|
| 147 |
btn_pdf.click(oracle_pdf, inputs=pdf_in, outputs=pdf_out)
|