nashjiwani commited on
Commit
bc5c025
·
verified ·
1 Parent(s): e35ec9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -75
app.py CHANGED
@@ -1,147 +1,147 @@
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
- import fitz # PyMuPDF for PDF reading
5
 
6
  # -------------------------------
7
- # Load Models
8
  # -------------------------------
9
- # Text AI detector
10
  text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
11
-
12
- # Image classifier (placeholder for "AI detection", but works publicly)
13
  image_analyzer = pipeline("image-classification", model="microsoft/resnet-50")
14
-
15
- # Whisper tiny for audio transcription
16
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
17
 
18
  # -------------------------------
19
- # Oracle Function
20
  # -------------------------------
21
  @spaces.GPU
22
  def oracle_prophecy(user_text, user_img, user_audio, user_pdf):
23
-
24
  prophecy = ""
25
 
26
- # TEXT check
27
  if user_text and user_text.strip():
28
  result = text_detector(user_text)
29
  label = result[0]['label']
30
  score = round(result[0]['score'] * 100, 2)
31
- if label.lower() == "fake":
32
- prophecy += f"📜 Text: 🌌 **Prophecy:** {score}% AI‑generated 🤖✨\n\n"
33
- else:
34
- prophecy += f"📜 Text: ☀️ **Prophecy:** {score}% Human‑written 🧑‍💻\n\n"
 
35
 
36
- # IMAGE check
37
  if user_img is not None:
38
  result = image_analyzer(user_img)
39
  label = result[0]['label']
40
  score = round(result[0]['score'] * 100, 2)
41
- prophecy += f"🖼️ Image: Oracle’s Sight → {score}% match with **{label}** 🌠\n\n"
42
 
43
- # AUDIO check
44
  if user_audio is not None:
45
  transcript = asr_pipe(user_audio)["text"]
46
  result = text_detector(transcript)
47
  label = result[0]['label']
48
  score = round(result[0]['score'] * 100, 2)
49
- if label.lower() == "fake":
50
- prophecy += f"🔊 Voice transcript: *{transcript}*🌌 {score}% AI‑generated 🤖\n\n"
51
- else:
52
- prophecy += f"🔊 Voice transcript: *{transcript}*☀️ {score}% Human‑spoken 🧑‍💻\n\n"
 
53
 
54
  # PDF check
55
  if user_pdf is not None:
56
  doc = fitz.open(user_pdf)
57
  text = "".join([page.get_text() for page in doc])
58
  if text.strip():
59
- result = text_detector(text[:800]) # only analyze first 800 chars
60
  label = result[0]['label']
61
  score = round(result[0]['score'] * 100, 2)
62
- if label.lower() == "fake":
63
- prophecy += f"📑 PDF: 🌌 Prophecy: {score}% AI‑generated 🤖\n\n"
64
- else:
65
- prophecy += f"📑 PDF: ☀️ Prophecy: {score}% Human‑authored 🧑‍💻\n\n"
 
66
  else:
67
- prophecy += "📑 PDF: ⚠️ No readable text found.\n\n"
68
 
69
  if prophecy.strip() == "":
70
- prophecy = "⚠️ Please provide text, image, audio, or PDF for the Oracle."
71
 
72
- return f"<div class='result-box'>{prophecy}</div>"
73
 
74
  # -------------------------------
75
- # Gradio UI (Theme like AwesomePet‑Talk)
76
  # -------------------------------
77
  with gr.Blocks(css="""
78
- /* Background Gradient */
79
  body {
80
- background: linear-gradient(135deg, #fbc2eb, #a6c1ee);
81
  font-family: 'Trebuchet MS', sans-serif;
82
- color: #2c003e;
83
  text-align: center;
 
 
84
  }
85
 
86
- /* Title + subtitle */
87
  #title {
88
  font-size: 3em !important;
89
- color: #ff0080;
90
- text-shadow: 2px 2px 8px #00000055;
91
- margin-top: 20px;
92
  }
 
 
93
  #subtitle {
94
- font-size: 1.4em !important;
95
- color: #4b0082;
96
- margin-bottom: 20px;
97
  }
98
 
99
- /* Bigger inputs */
 
 
 
 
100
  textarea, input, .gr-textbox {
101
  font-size: 1.2em !important;
102
  }
103
 
104
- /* Results Box */
 
 
 
 
 
 
 
 
 
 
 
105
  .result-box {
106
- background: rgba(255,255,255,0.95);
107
- border-radius: 20px;
108
- padding: 20px;
109
- margin-top: 25px;
110
- font-size: 1.4em;
111
- color: #222;
112
- box-shadow: 0px 4px 15px rgba(0,0,0,0.3);
113
- text-align: left;
114
- white-space: pre-line;
115
  }
116
  """) as demo:
117
 
118
- # Title
119
  gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
120
- gr.HTML("<div id='subtitle'>✨ Offer your text, image, voice, or PDF receive the Oracle's prophecy ✨</div>")
121
-
122
- gr.Markdown("""
123
- 👋 Welcome, Seeker!
124
-
125
- Place your offerings before the Oracle:
126
- - 📜 Paste *text* (essay, blog, email, story)
127
- - 🖼️ Upload an *image*
128
- - 🔊 Speak with your *voice*
129
- - 📑 Upload a *PDF*
130
-
131
- Then click **Reveal Prophecy ✨** and watch the Oracle’s vision unfold.
132
- """)
133
 
134
- with gr.Row():
135
- with gr.Column():
136
- txt_in = gr.Textbox(lines=6, label="📝 Text Offering")
137
- img_in = gr.Image(type="filepath", label="🖼️ Image Offering")
138
- aud_in = gr.Audio(sources=["microphone"], type="filepath", label="🎤 Voice Offering")
139
- pdf_in = gr.File(file_types=[".pdf"], label="📄 PDF Offering")
140
- btn = gr.Button("✨ Reveal Prophecy", variant="primary")
141
 
142
- with gr.Column():
143
- result = gr.HTML(label="Oracle's Prophecy")
144
 
145
- btn.click(oracle_prophecy, inputs=[txt_in, img_in, aud_in, pdf_in], outputs=result)
146
 
147
  demo.launch()
 
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
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
+ # Main Oracle Function
15
  # -------------------------------
16
  @spaces.GPU
17
  def oracle_prophecy(user_text, user_img, user_audio, user_pdf):
 
18
  prophecy = ""
19
 
20
+ # Text check
21
  if user_text and user_text.strip():
22
  result = text_detector(user_text)
23
  label = result[0]['label']
24
  score = round(result[0]['score'] * 100, 2)
25
+ prophecy += (
26
+ f"📜 **Text Prophecy:** {score}% AI‑generated 🤖✨\n\n"
27
+ if label.lower() == "fake"
28
+ else f"📜 **Text Prophecy:** {score}% Human‑written 🧑‍💻\n\n"
29
+ )
30
 
31
+ # Image check
32
  if user_img is not None:
33
  result = image_analyzer(user_img)
34
  label = result[0]['label']
35
  score = round(result[0]['score'] * 100, 2)
36
+ prophecy += f"🖼️ **Image Prophecy:** {score}% match with {label} 🌠\n\n"
37
 
38
+ # Audio check
39
  if user_audio is not None:
40
  transcript = asr_pipe(user_audio)["text"]
41
  result = text_detector(transcript)
42
  label = result[0]['label']
43
  score = round(result[0]['score'] * 100, 2)
44
+ prophecy += (
45
+ f"🔊 Transcript: *{transcript}*\n🌌 Prophecy: {score}% AI‑generated 🤖\n\n"
46
+ if label.lower() == "fake"
47
+ else f"🔊 Transcript: *{transcript}*\n☀️ Prophecy: {score}% Human‑spoken 🧑‍💻\n\n"
48
+ )
49
 
50
  # PDF check
51
  if user_pdf is not None:
52
  doc = fitz.open(user_pdf)
53
  text = "".join([page.get_text() for page in doc])
54
  if text.strip():
55
+ result = text_detector(text[:800])
56
  label = result[0]['label']
57
  score = round(result[0]['score'] * 100, 2)
58
+ prophecy += (
59
+ f"📑 **PDF Prophecy:** {score}% AI‑generated 🤖\n\n"
60
+ if label.lower() == "fake"
61
+ else f"📑 **PDF Prophecy:** {score}% Human‑authored 🧑‍💻\n\n"
62
+ )
63
  else:
64
+ prophecy += "📑 No readable text in PDF.\n\n"
65
 
66
  if prophecy.strip() == "":
67
+ prophecy = "⚠️ Please provide text, image, voice, or PDF to the Oracle."
68
 
69
+ return prophecy
70
 
71
  # -------------------------------
72
+ # UI Inspired by BeatBreak
73
  # -------------------------------
74
  with gr.Blocks(css="""
75
+ /* Background */
76
  body {
77
+ background: linear-gradient(135deg, #667eea, #764ba2);
78
  font-family: 'Trebuchet MS', sans-serif;
79
+ color: #fff !important;
80
  text-align: center;
81
+ margin: 0;
82
+ padding: 0;
83
  }
84
 
85
+ /* Title */
86
  #title {
87
  font-size: 3em !important;
88
+ color: #FFD700 !important;
89
+ text-shadow: 2px 2px 8px #000 !important;
90
+ margin: 20px 0;
91
  }
92
+
93
+ /* Subtitle */
94
  #subtitle {
95
+ font-size: 1.5em !important;
96
+ color: #E0FFFF !important;
97
+ margin-bottom: 30px;
98
  }
99
 
100
+ /* Input labels + fields */
101
+ label {
102
+ font-size: 1.3em !important;
103
+ color: #fff !important;
104
+ }
105
  textarea, input, .gr-textbox {
106
  font-size: 1.2em !important;
107
  }
108
 
109
+ /* Big button style */
110
+ button {
111
+ font-size: 1.4em !important;
112
+ padding: 12px 28px !important;
113
+ border-radius: 12px !important;
114
+ background: linear-gradient(90deg, #ff8a00, #e52e71) !important;
115
+ color: #fff !important;
116
+ font-weight: bold !important;
117
+ border: none !important;
118
+ }
119
+
120
+ /* Result Box */
121
  .result-box {
122
+ background: rgba(255, 255, 255, 0.95) !important;
123
+ border-radius: 20px !important;
124
+ padding: 30px !important;
125
+ margin-top: 30px !important;
126
+ font-size: 1.5em !important;
127
+ color: #222 !important;
128
+ box-shadow: 0px 4px 20px rgba(0,0,0,0.4) !important;
129
+ text-align: left !important;
130
+ white-space: pre-line !important;
131
  }
132
  """) as demo:
133
 
 
134
  gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
135
+ gr.HTML("<div id='subtitle'>✨ Offer Text · Image · Voice · PDF to Reveal the Prophecy ✨</div>")
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ txt_in = gr.Textbox(lines=4, label="📜 Text Offering")
138
+ img_in = gr.Image(type="filepath", label="🖼️ Image Offering")
139
+ aud_in = gr.Audio(sources=["microphone"], type="filepath", label="🔊 Voice Offering")
140
+ pdf_in = gr.File(file_types=[".pdf"], label="📑 PDF Offering")
 
 
 
141
 
142
+ btn = gr.Button("✨ Reveal Prophecy")
143
+ output = gr.HTML(elem_classes="result-box")
144
 
145
+ btn.click(oracle_prophecy, [txt_in, img_in, aud_in, pdf_in], output)
146
 
147
  demo.launch()