Spaces:
Paused
Paused
| 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 | |
| # ------------------------------- | |
| 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" | |
| ) | |
| 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() |