Spaces:
Paused
Paused
File size: 4,815 Bytes
4d664c8 42b42e0 689097b 2bac179 4d664c8 b8c713e bc5c025 b8c713e 689097b b8a65e7 bebb2f2 b8a65e7 2bac179 b8a65e7 689097b e35ec9c b8a65e7 2bac179 e35ec9c 2bac179 bc5c025 b8a65e7 2bac179 e35ec9c 2bac179 bc5c025 e35ec9c 2bac179 e35ec9c 2bac179 bc5c025 e35ec9c 2bac179 e35ec9c bc5c025 2bac179 bc5c025 e35ec9c 2bac179 e35ec9c 2bac179 e35ec9c bc5c025 bebb2f2 b8c713e 2bac179 b8c713e 2bac179 c00c2d7 bc5c025 c13578f bc5c025 2bac179 b8a65e7 e35ec9c 2bac179 e35ec9c c13578f bc5c025 2bac179 b8a65e7 e35ec9c bc5c025 c00c2d7 e35ec9c 2bac179 bc5c025 2bac179 bc5c025 c13578f dd88c6b 2bac179 e35ec9c 2bac179 bc5c025 2bac179 bc5c025 2bac179 bc5c025 c13578f 2bac179 c00c2d7 b8c713e 2bac179 e35ec9c 2bac179 e35ec9c 2bac179 e35ec9c 2bac179 337686c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import gradio as gr
import spaces
from transformers import pipeline
import fitz # PyMuPDF for PDF reading
# -------------------------------
# Models
# -------------------------------
text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
image_analyzer = pipeline("image-classification", model="microsoft/resnet-50")
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
# -------------------------------
# Oracle Main Function
# -------------------------------
@spaces.GPU
def oracle_prophecy(user_text, user_img, user_audio, user_pdf):
prophecy = ""
# Text
if user_text and user_text.strip():
result = text_detector(user_text)
label = result[0]["label"]
score = round(result[0]["score"] * 100, 2)
prophecy += (
f"📜 **Text Prophecy:** {score}% AI‑generated 🤖✨\n\n"
if label.lower() == "fake"
else f"📜 **Text Prophecy:** {score}% Human‑written 🧑💻\n\n"
)
# Image
if user_img is not None:
result = image_analyzer(user_img)
label = result[0]["label"]
score = round(result[0]["score"] * 100, 2)
prophecy += f"🖼️ **Image Prophecy:** {score}% match with {label} 🌠\n\n"
# Audio
if user_audio is not None:
transcript = asr_pipe(user_audio)["text"]
result = text_detector(transcript)
label = result[0]["label"]
score = round(result[0]["score"] * 100, 2)
prophecy += (
f"🔊 Transcript: *{transcript}*\n🌌 Prophecy: {score}% AI‑generated 🤖✨\n\n"
if label.lower() == "fake"
else f"🔊 Transcript: *{transcript}*\n☀️ Prophecy: {score}% Human‑spoken 🧑💻\n\n"
)
# PDF
if user_pdf is not None:
doc = fitz.open(user_pdf)
text = "".join([page.get_text() for page in doc])
if text.strip():
result = text_detector(text[:800])
label = result[0]["label"]
score = round(result[0]["score"] * 100, 2)
prophecy += (
f"📑 **PDF Prophecy:** {score}% AI‑generated 🤖✨\n\n"
if label.lower() == "fake"
else f"📑 **PDF Prophecy:** {score}% Human‑authored 🧑💻\n\n"
)
else:
prophecy += "📑 PDF: ⚠️ No readable text found.\n\n"
if prophecy.strip() == "":
prophecy = "⚠️ Please provide text, an image, a voice file, or a PDF."
return prophecy
# -------------------------------
# Gradio UI (Aligned Card Style like Beat‑Break)
# -------------------------------
with gr.Blocks(css="""
/* Background and Base */
body {
background: linear-gradient(135deg, #667eea, #764ba2);
font-family: 'Trebuchet MS', sans-serif;
margin: 0;
padding: 0;
color: #fff;
text-align: center;
}
/* Container to center, shrink width */
.container {
max-width: 900px;
margin: 0 auto;
padding: 20px;
}
/* Title + Subtitle */
#title {
font-size: 3em !important;
color: #FFD700 !important;
text-shadow: 2px 2px 8px #000;
margin-bottom: 10px;
}
#subtitle {
font-size: 1.5em !important;
color: #E0FFFF !important;
margin-bottom: 30px;
}
/* Inputs */
label {
font-size: 1.2em !important;
color: #fff !important;
}
textarea, input, .gr-textbox {
font-size: 1.2em !important;
}
audio, .gr-file, .gr-image {
margin-bottom: 20px;
}
/* Button */
button {
font-size: 1.3em !important;
padding: 12px 28px !important;
border-radius: 12px !important;
background: linear-gradient(90deg, #ff8a00, #e52e71) !important;
color: #fff !important;
font-weight: bold !important;
border: none !important;
margin-top: 20px;
}
button:hover {
opacity: 0.9;
box-shadow: 0 0 20px #FFD700;
}
/* Result Box */
.result-box {
background: #fff;
border-radius: 20px;
padding: 25px;
margin: 30px auto;
font-size: 1.4em;
color: #222;
box-shadow: 0px 6px 20px rgba(0,0,0,0.4);
text-align: left;
white-space: pre-line;
}
""") as demo:
with gr.Column(elem_classes="container"):
gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
gr.HTML("<div id='subtitle'>✨ Offer Text · Image · Voice File · PDF ✨</div>")
txt_in = gr.Textbox(lines=4, label="📜 Text Offering")
img_in = gr.Image(type="filepath", label="🖼️ Image Offering")
# VOICE: file upload only
aud_in = gr.File(file_types=[".wav", ".mp3"], label="🔊 Voice File Offering")
pdf_in = gr.File(file_types=[".pdf"], label="📑 PDF Offering")
btn = gr.Button("✨ Reveal Prophecy")
output = gr.HTML(elem_classes="result-box")
btn.click(oracle_prophecy, [txt_in, img_in, aud_in, pdf_in], output)
demo.launch() |