nashjiwani commited on
Commit
0a8d5ac
·
verified ·
1 Parent(s): bcd9a29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -122
app.py CHANGED
@@ -1,149 +1,63 @@
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):
31
- if user_img is None:
32
- return "⚠️ Please upload an image!"
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):
40
- if audio_file is None:
41
- return "⚠️ Please record your voice."
42
- transcript = asr_pipe(audio_file)["text"]
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
54
- def oracle_pdf(pdf_file):
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)
148
 
149
  demo.launch()
 
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
+ import fitz # PDF
5
 
6
  # -------------------------------
7
+ # Model load
8
  # -------------------------------
9
  text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
 
 
10
 
 
 
 
11
  @spaces.GPU
12
  def oracle_text(user_text: str):
13
  if not user_text.strip():
14
+ return "⚠️ Please enter text."
15
  result = text_detector(user_text)
16
  label = result[0]['label']
17
  score = round(result[0]['score'] * 100, 2)
18
+ if label.lower() == "fake":
19
+ return f"🌌 **Prophecy:** {score}% AI‑generated 🤖✨"
20
+ else:
21
+ return f"☀️ **Prophecy:** {score}% Human‑written 🧑‍💻"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # -------------------------------
24
+ # UI
25
  # -------------------------------
26
  with gr.Blocks(css="""
27
  body {
28
+ background: linear-gradient(135deg, #ff9a9e, #fad0c4, #a1c4fd, #c2e9fb);
29
+ font-family: 'Trebuchet MS', sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
+ #title { text-align: center; font-size: 2.8em; color: #FFD700; text-shadow: 2px 2px 6px black; }
32
+ #subtitle { text-align: center; font-size: 1.3em; color: #00FFFF; margin-bottom: 20px; }
33
  .result-box {
34
+ background: rgba(0,0,0,0.7);
35
+ border-radius: 15px;
36
+ padding: 20px;
37
+ font-size: 1.4em;
38
+ color: #FFFFFF;
39
+ box-shadow: 0 0 15px #FFD700;
40
+ margin-top: 15px;
41
  }
42
  """) as demo:
43
 
44
  gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
45
+ gr.HTML("<div id='subtitle'>Offer your text and receive a glowing prophecy ✨</div>")
46
+
47
+ txt_in = gr.Textbox(lines=8, label="📝 Your Text", placeholder="Paste an essay, blog, or message…")
48
+ btn = gr.Button("✨ Reveal Prophecy", variant="primary")
49
+ txt_out = gr.Markdown(elem_classes="result-box")
50
+
51
+ btn.click(oracle_text, inputs=txt_in, outputs=txt_out)
52
+
53
+ gr.Examples(
54
+ examples=[
55
+ ["Once upon a time in a galaxy far away…"],
56
+ ["Artificial Intelligence is reshaping industries globally 🌍"],
57
+ ["LOL can't believe it's Monday again 😅"],
58
+ ["This manuscript evaluates Transformer models for classification."]
59
+ ],
60
+ inputs=txt_in,
61
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  demo.launch()