nashjiwani commited on
Commit
bebb2f2
ยท
verified ยท
1 Parent(s): 337686c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -57
app.py CHANGED
@@ -1,102 +1,161 @@
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
 
4
 
5
  # -------------------------------
6
- # Load Text AI Detector
7
  # -------------------------------
 
8
  text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
9
 
 
 
 
 
 
 
10
  # -------------------------------
11
- # Oracle Function
12
  # -------------------------------
 
13
  @spaces.GPU
14
  def oracle_text(user_text: str):
15
  if not user_text or not user_text.strip():
16
- return "๐Ÿงž Please provide some text for the Oracle to examine."
17
-
18
  result = text_detector(user_text)
19
  label = result[0]['label']
20
  score = round(result[0]['score'] * 100, 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
 
 
 
 
 
 
 
 
22
  if label.lower() == "fake":
23
- verdict = f"๐ŸŒŒ **Prophecy:** {score}% chance this was **conjured by AI sorcery** ๐Ÿค–โœจ"
24
  else:
25
- verdict = f"โ˜€๏ธ **Prophecy:** {score}% chance this was **crafted by a mortal hand** ๐Ÿง‘โ€๐Ÿ’ป"
26
-
27
  return verdict
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # -------------------------------
30
  # Gradio Immersive UI
31
  # -------------------------------
32
  with gr.Blocks(css="""
33
  body {
34
- background: linear-gradient(135deg, #0f2027, #2c5364);
35
  font-family: 'Trebuchet MS', sans-serif;
36
  color: white;
37
  }
38
  #title {
39
  text-align: center;
40
- font-size: 2.5em;
41
  color: #FFD700;
42
  padding: 20px;
 
43
  }
44
  #subtitle {
45
  text-align: center;
46
  font-size: 1.3em;
47
  color: #E0FFFF;
48
- margin-bottom: 30px;
49
  }
50
- textarea, input, .gr-textbox {
51
- font-size: 1.1em !important;
 
 
 
 
 
 
52
  }
53
  """) as demo:
54
 
55
- # Title and intro
56
  gr.HTML("<div id='title'>๐Ÿ”ฎ Oracle of Truth ๐Ÿ”ฎ</div>")
57
- gr.HTML("<div id='subtitle'>Enter the Chamber of Truth โœจ</div>")
58
-
59
- gr.Markdown(
60
- """
61
- Welcome, traveler ๐ŸŒŒ
62
-
63
- This chamber is home to the **Oracle of Truth**, an ancient AI seer that discerns whether words were born of **mortal minds** ๐Ÿง‘โ€๐Ÿ’ป
64
- or conjured by the **forges of artificial sorcery** ๐Ÿค–โœจ
65
-
66
- ### ๐Ÿ“– **How to use this Space**
67
- - Paste **any text**: essays, blogs, social posts, code comments, even AI prompts.
68
- - Press **โ€œReveal Truthโ€** and await the Oracleโ€™s prophecy.
69
- - The Oracle will divine the **likelihood** that your offering was humanโ€‘written or AIโ€‘generated.
70
-
71
- ### ๐ŸŒŸ Pro Tips
72
- - Try both short and long texts.
73
- - Compare a paragraph you wrote vs one generated by ChatGPT or another AI.
74
- - Share the Oracleโ€™s flameโ€‘lit verdict screenshots with friends ๐Ÿ”ฅ
75
- """
76
- )
77
-
78
- with gr.Row():
79
- with gr.Column(scale=1):
80
- txt_in = gr.Textbox(
81
- label="๐Ÿ“ Offer your text to the Oracle",
82
- lines=10,
83
- placeholder="Paste your story, essay, or blog draft here..."
84
- )
85
- btn_txt = gr.Button("๐Ÿ” Reveal Truth", variant="primary")
86
- txt_out = gr.Markdown(label="๐Ÿ”ฎ Oracle's Prophecy")
87
-
88
- btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
89
-
90
- gr.Markdown("### โœจ Try these prophecies:")
91
-
92
- gr.Examples(
93
- examples=[
94
- ["Once upon a time, in a galaxy far away, a hero rose to fight destiny."],
95
- ["Artificial intelligence is a transformative technology reshaping industries globally."],
96
- ["OMG lol I canโ€™t believe itโ€™s already Monday again ๐Ÿ˜…"],
97
- ["This research paper presents a thorough analysis of Transformer models on sentiment classification tasks."]
98
- ],
99
- inputs=txt_in,
100
- )
 
 
 
 
 
 
101
 
102
  demo.launch()
 
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
+ import fitz # PyMuPDF for PDF extraction
5
 
6
  # -------------------------------
7
+ # Load Models
8
  # -------------------------------
9
+ # Text detector (public)
10
  text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
11
 
12
+ # Image classifier (public baseline, since AI-specific detectors are often gated)
13
+ image_analyzer = pipeline("image-classification", model="microsoft/resnet-50")
14
+
15
+ # Whisper tiny for audio โ†’ text transcription
16
+ asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
17
+
18
  # -------------------------------
19
+ # Oracle Functions
20
  # -------------------------------
21
+
22
  @spaces.GPU
23
  def oracle_text(user_text: str):
24
  if not user_text or not user_text.strip():
25
+ return "โš ๏ธ Please provide some text for the Oracle."
 
26
  result = text_detector(user_text)
27
  label = result[0]['label']
28
  score = round(result[0]['score'] * 100, 2)
29
+ if label.lower() == "fake":
30
+ return f"๐ŸŒŒ **Prophecy:** {score}% chance this was **conjured by AI sorcery** ๐Ÿค–โœจ"
31
+ else:
32
+ return f"โ˜€๏ธ **Prophecy:** {score}% chance this was **crafted by a mortal hand** ๐Ÿง‘โ€๐Ÿ’ป"
33
+
34
+ @spaces.GPU
35
+ def oracle_image(user_img):
36
+ if user_img is None:
37
+ return "โš ๏ธ Please upload an image!"
38
+ result = image_analyzer(user_img)
39
+ label = result[0]['label']
40
+ score = round(result[0]['score'] * 100, 2)
41
+ return f"๐ŸŒ  **Oracleโ€™s Gaze:** {score}% resemblance to *{label}*.\n(Note: Image prophecy = experimental ๐ŸŒŒ)"
42
 
43
+ @spaces.GPU
44
+ def oracle_audio(audio_file):
45
+ if audio_file is None:
46
+ return "โš ๏ธ Please record your voice."
47
+ transcript = asr_pipe(audio_file)["text"]
48
+ result = text_detector(transcript)
49
+ label = result[0]['label']
50
+ score = round(result[0]['score'] * 100, 2)
51
  if label.lower() == "fake":
52
+ verdict = f"๐Ÿ”Š Transcript: *{transcript}*\n\n๐ŸŒŒ Prophecy: {score}% AI-generated."
53
  else:
54
+ verdict = f"๐Ÿ”Š Transcript: *{transcript}*\n\nโ˜€๏ธ Prophecy: {score}% Human-written."
 
55
  return verdict
56
 
57
+ @spaces.GPU
58
+ def oracle_pdf(pdf_file):
59
+ if pdf_file is None:
60
+ return "โš ๏ธ Please upload a PDF."
61
+ doc = fitz.open(pdf_file)
62
+ text = ""
63
+ for page in doc:
64
+ text += page.get_text()
65
+ if not text.strip():
66
+ return "โš ๏ธ Could not extract text from PDF."
67
+ # Detect
68
+ result = text_detector(text[:800]) # limit chars for speed
69
+ label = result[0]['label']
70
+ score = round(result[0]['score'] * 100, 2)
71
+ if label.lower() == "fake":
72
+ return f"๐Ÿ“‘ PDF Analysis: {score}% chance this was made by AI ๐Ÿค–"
73
+ else:
74
+ return f"๐Ÿ“‘ PDF Analysis: {score}% chance this was human-authored ๐Ÿง‘โ€๐Ÿ’ป"
75
+
76
  # -------------------------------
77
  # Gradio Immersive UI
78
  # -------------------------------
79
  with gr.Blocks(css="""
80
  body {
81
+ background: linear-gradient(135deg, #ff9a9e, #fad0c4, #a18cd1, #fbc2eb);
82
  font-family: 'Trebuchet MS', sans-serif;
83
  color: white;
84
  }
85
  #title {
86
  text-align: center;
87
+ font-size: 2.8em;
88
  color: #FFD700;
89
  padding: 20px;
90
+ text-shadow: 2px 2px 5px #000;
91
  }
92
  #subtitle {
93
  text-align: center;
94
  font-size: 1.3em;
95
  color: #E0FFFF;
96
+ margin-bottom: 20px;
97
  }
98
+ .result-box {
99
+ background: rgba(255, 255, 255, 0.2);
100
+ border-radius: 15px;
101
+ padding: 20px;
102
+ font-size: 1.3em;
103
+ color: #fff;
104
+ margin-top: 10px;
105
+ box-shadow: 0px 0px 15px #FFD700;
106
  }
107
  """) as demo:
108
 
 
109
  gr.HTML("<div id='title'>๐Ÿ”ฎ Oracle of Truth ๐Ÿ”ฎ</div>")
110
+ gr.HTML("<div id='subtitle'>Offer your text, image, voice, or PDF to the Oracle โœจ</div>")
111
+
112
+ gr.Markdown("""
113
+ Welcome, seeker ๐ŸŒŒ
114
+
115
+ The **Oracle of Truth** gazes upon your offering and divines whether it was born of
116
+ a **mortal hand** โ˜€๏ธ or conjured by **AI sorcery** ๐Ÿค–โœจ.
117
+
118
+ ## ๐ŸŒŸ How to Use
119
+ - ๐Ÿ“œ Paste text in the **Text Divination** panel.
120
+ - ๐Ÿ–ผ๏ธ Upload images in the **Image Prophecy** panel.
121
+ - ๐Ÿ”Š Speak into the **Voice Revelation** panel.
122
+ - ๐Ÿ“‘ Offer a **PDF** to see if it was written by human or AI.
123
+
124
+ The Oracle responds in glowing prophecy form โ€” watch carefully ๐Ÿ‘๏ธ
125
+ """)
126
+
127
+ with gr.Tab("๐Ÿ“œ Text Divination"):
128
+ txt_in = gr.Textbox(lines=10, label="Your Text โœ๏ธ", placeholder="Paste story, essay, or blogโ€ฆ")
129
+ btn_txt = gr.Button("โœจ Reveal Prophecy", variant="primary")
130
+ txt_out = gr.Markdown(elem_classes="result-box")
131
+ btn_txt.click(oracle_text, inputs=txt_in, outputs=txt_out)
132
+
133
+ gr.Examples(
134
+ examples=[
135
+ ["Once upon a time in a galaxyโ€ฆ"],
136
+ ["AI is revolutionizing the world of education and technology."],
137
+ ["OMG I canโ€™t believe itโ€™s already Monday ๐Ÿ˜…"],
138
+ ["This paper provides an extensive overview of machine translation performance."]
139
+ ],
140
+ inputs=txt_in
141
+ )
142
+
143
+ with gr.Tab("๐Ÿ–ผ๏ธ Image Prophecy"):
144
+ img_in = gr.Image(type="filepath", label="Upload Image ๐Ÿ–ผ๏ธ")
145
+ btn_img = gr.Button("โœจ Reveal Prophecy", variant="primary")
146
+ img_out = gr.Markdown(elem_classes="result-box")
147
+ btn_img.click(oracle_image, inputs=img_in, outputs=img_out)
148
+
149
+ with gr.Tab("๐Ÿ”Š Voice Revelation"):
150
+ aud_in = gr.Audio(sources=["microphone"], type="filepath", label="Speak Now ๐ŸŽ™๏ธ")
151
+ btn_aud = gr.Button("โœจ Reveal Prophecy", variant="primary")
152
+ aud_out = gr.Markdown(elem_classes="result-box")
153
+ btn_aud.click(oracle_audio, inputs=aud_in, outputs=aud_out)
154
+
155
+ with gr.Tab("๐Ÿ“‘ PDF Prophecy"):
156
+ pdf_in = gr.File(label="Upload PDF ๐Ÿ“„", file_types=[".pdf"])
157
+ btn_pdf = gr.Button("โœจ Reveal Prophecy", variant="primary")
158
+ pdf_out = gr.Markdown(elem_classes="result-box")
159
+ btn_pdf.click(oracle_pdf, inputs=pdf_in, outputs=pdf_out)
160
 
161
  demo.launch()