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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +125 -36
app.py CHANGED
@@ -1,63 +1,152 @@
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()
 
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
+ import fitz # PyMuPDF for PDF
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
+ # Oracle Functions
15
+ # -------------------------------
16
  @spaces.GPU
17
  def oracle_text(user_text: str):
18
  if not user_text.strip():
19
+ return "⚠️ Please provide 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}% AI‑generated 🤖✨"
25
+ if label.lower() == "fake"
26
+ else f"☀️ **Prophecy:** {score}% Human‑written 🧑‍💻"
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*(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 text found in PDF."
61
+ result = text_detector(text[:800]) # limit to 800 chars
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
+ # UI Styling + Layout
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: #FFFFFF;
78
+ }
79
+ #title {
80
+ text-align: center;
81
+ font-size: 3em;
82
+ color: #FFD700;
83
+ padding: 20px;
84
+ text-shadow: 2px 2px 8px #000;
85
+ }
86
+ #subtitle {
87
+ text-align: center;
88
+ font-size: 1.4em;
89
+ color: #00FFFF;
90
+ margin-bottom: 25px;
91
  }
 
 
92
  .result-box {
93
+ background: rgba(0, 0, 0, 0.7);
94
+ border-radius: 15px;
95
+ padding: 20px;
96
+ font-size: 1.4em;
97
+ color: #FFFFFF;
98
+ box-shadow: 0 0 15px #FFD700;
99
+ margin-top: 15px;
100
+ }
101
+ .gr-textbox textarea {
102
+ font-size: 1.1em !important;
103
  }
104
  """) as demo:
105
 
106
  gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
107
+ gr.HTML("<div id='subtitle'>Multi‑Sight Divination Text · Image · Voice · PDF</div>")
108
+
109
+ gr.Markdown("""
110
+ 👋 **Welcome, Seeker!**
111
+
112
+ The Oracle gazes upon your offering — whether **text**, **image**, **voice**, or **PDF** —
113
+ and reveals its prophecy: 🧑‍💻 Human‑born ☀️ or 🤖 Machine‑conjured.
114
+
115
+ 👉 Choose a panel below and witness the verdict in a glowing prophecy box.
116
+ """)
117
+
118
+ with gr.Tab("📜 Text Divination"):
119
+ txt_in = gr.Textbox(lines=8, label="Your Text ✍️", placeholder="Paste essay, story, blog, email...")
120
+ btn_txt = gr.Button("✨ Reveal Prophecy", variant="primary")
121
+ txt_out = gr.Markdown(elem_classes="result-box")
122
+ btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
123
+
124
+ gr.Examples(
125
+ examples=[
126
+ ["Once upon a time in a galaxy far away…"],
127
+ ["Artificial Intelligence is revolutionizing healthcare globally 🌍"],
128
+ ["LOL can't believe it's Monday again 😅"],
129
+ ["This manuscript provides a rigorous evaluation of Transformer architectures."]
130
+ ],
131
+ inputs=txt_in
132
+ )
133
+
134
+ with gr.Tab("🖼️ Image Prophecy"):
135
+ img_in = gr.Image(type="filepath", label="Upload an Image 🖼️")
136
+ btn_img = gr.Button("✨ Reveal Prophecy", variant="primary")
137
+ img_out = gr.Markdown(elem_classes="result-box")
138
+ btn_img.click(oracle_image, inputs=img_in, outputs=img_out)
139
+
140
+ with gr.Tab("🔊 Voice Revelation"):
141
+ aud_in = gr.Audio(sources=["microphone"], type="filepath", label="🎙️ Speak your truth")
142
+ btn_aud = gr.Button("✨ Reveal Prophecy", variant="primary")
143
+ aud_out = gr.Markdown(elem_classes="result-box")
144
+ btn_aud.click(oracle_audio, inputs=aud_in, outputs=aud_out)
145
+
146
+ with gr.Tab("📑 PDF Prophecy"):
147
+ pdf_in = gr.File(label="📄 Upload PDF", file_types=[".pdf"])
148
+ btn_pdf = gr.Button("✨ Reveal Prophecy", variant="primary")
149
+ pdf_out = gr.Markdown(elem_classes="result-box")
150
+ btn_pdf.click(oracle_pdf, inputs=pdf_in, outputs=pdf_out)
151
 
152
  demo.launch()