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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -55
app.py CHANGED
@@ -4,14 +4,14 @@ 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):
@@ -21,9 +21,9 @@ def oracle_text(user_text: str):
21
  label = result[0]['label']
22
  score = round(result[0]['score'] * 100, 2)
23
  return (
24
- f"🌌 **Prophecy:** {score}% AIgenerated 🤖✨"
25
- if label.lower() == "fake"
26
- else f"☀️ **Prophecy:** {score}% Humanwritten 🧑‍💻"
27
  )
28
 
29
  @spaces.GPU
@@ -33,7 +33,7 @@ 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*(experimental 🌌)*"
37
 
38
  @spaces.GPU
39
  def oracle_audio(audio_file):
@@ -44,9 +44,9 @@ def oracle_audio(audio_file):
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
 
@@ -58,30 +58,29 @@ def oracle_pdf(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;
@@ -89,64 +88,56 @@ body {
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()
 
4
  import fitz # PyMuPDF for PDF
5
 
6
  # -------------------------------
7
+ # 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):
 
21
  label = result[0]['label']
22
  score = round(result[0]['score'] * 100, 2)
23
  return (
24
+ f"<div class='prophecy human'>☀️ Prophecy: {score}% Humanwritten 🧑‍💻</div>"
25
+ if label.lower() == "real" or label.lower() == "human"
26
+ else f"<div class='prophecy ai'>🌌 Prophecy: {score}% AIgenerated 🤖✨</div>"
27
  )
28
 
29
  @spaces.GPU
 
33
  result = image_analyzer(user_img)
34
  label = result[0]['label']
35
  score = round(result[0]['score'] * 100, 2)
36
+ return f"<div class='prophecy image'>🖼️ Oracle’s Sight: {score}% resemblance to <b>{label}</b> 🌠</div>"
37
 
38
  @spaces.GPU
39
  def oracle_audio(audio_file):
 
44
  label = result[0]['label']
45
  score = round(result[0]['score'] * 100, 2)
46
  verdict = (
47
+ f"<div class='prophecy ai'>🔊 Transcript: <i>{transcript}</i><br><br>🌌 Prophecy: {score}% AI‑generated 🤖</div>"
48
  if label.lower() == "fake"
49
+ else f"<div class='prophecy human'>🔊 Transcript: <i>{transcript}</i><br><br>☀️ Prophecy: {score}% Human‑written 🧑‍💻</div>"
50
  )
51
  return verdict
52
 
 
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])
62
  label = result[0]['label']
63
  score = round(result[0]['score'] * 100, 2)
64
  return (
65
+ f"<div class='prophecy ai'>📑 PDF Prophecy: {score}% AI‑generated 🤖</div>"
66
  if label.lower() == "fake"
67
+ else f"<div class='prophecy human'>📑 PDF Prophecy: {score}% Human‑authored 🧑‍💻</div>"
68
  )
69
 
70
  # -------------------------------
71
+ # 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
  }
78
  #title {
79
  text-align: center;
80
  font-size: 3em;
81
  color: #FFD700;
82
+ padding: 15px;
83
+ text-shadow: 3px 3px 10px #000;
84
  }
85
  #subtitle {
86
  text-align: center;
 
88
  color: #00FFFF;
89
  margin-bottom: 25px;
90
  }
91
+ .prophecy {
 
92
  border-radius: 15px;
93
+ padding: 25px;
94
+ font-size: 1.6em;
 
 
95
  margin-top: 15px;
96
+ text-align: center;
97
+ font-weight: bold;
98
+ }
99
+ .prophecy.human {
100
+ background: rgba(0, 128, 0, 0.7);
101
+ color: #fff;
102
+ box-shadow: 0 0 18px #00FF7F;
103
+ }
104
+ .prophecy.ai {
105
+ background: rgba(128, 0, 128, 0.7);
106
+ color: #fff;
107
+ box-shadow: 0 0 18px #FF00FF;
108
  }
109
+ .prophecy.image {
110
+ background: rgba(0,0,0,0.6);
111
+ color: #FFD700;
112
+ box-shadow: 0 0 15px #FFF176;
113
  }
114
  """) as demo:
115
 
116
  gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
117
+ gr.HTML("<div id='subtitle'>✨ Multi‑Sight: Text · Image · Voice · PDF ✨</div>")
 
 
 
 
 
 
 
 
 
118
 
119
  with gr.Tab("📜 Text Divination"):
120
+ txt_in = gr.Textbox(lines=8, label="Enter your text ✍️", placeholder="Paste essay, article, story…")
121
+ btn_txt = gr.Button("✨ Reveal Prophecy")
122
+ txt_out = gr.HTML()
123
  btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
124
 
 
 
 
 
 
 
 
 
 
 
125
  with gr.Tab("🖼️ Image Prophecy"):
126
+ img_in = gr.Image(type="filepath", label="Upload Image")
127
+ btn_img = gr.Button("✨ Reveal Prophecy")
128
+ img_out = gr.HTML()
129
  btn_img.click(oracle_image, inputs=img_in, outputs=img_out)
130
 
131
  with gr.Tab("🔊 Voice Revelation"):
132
+ aud_in = gr.Audio(sources=["microphone"], type="filepath", label="Speak here 🎙️")
133
+ btn_aud = gr.Button("✨ Reveal Prophecy")
134
+ aud_out = gr.HTML()
135
  btn_aud.click(oracle_audio, inputs=aud_in, outputs=aud_out)
136
 
137
  with gr.Tab("📑 PDF Prophecy"):
138
+ pdf_in = gr.File(file_types=[".pdf"], label="Upload PDF")
139
+ btn_pdf = gr.Button("✨ Reveal Prophecy")
140
+ pdf_out = gr.HTML()
141
  btn_pdf.click(oracle_pdf, inputs=pdf_in, outputs=pdf_out)
142
 
143
  demo.launch()