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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -47
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
- import fitz # PyMuPDF for PDF
5
 
6
  # -------------------------------
7
  # Models
@@ -11,137 +11,152 @@ 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 Beat‑Break
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()
 
1
  import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
+ import fitz # PyMuPDF for PDF reading
5
 
6
  # -------------------------------
7
  # Models
 
11
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
12
 
13
  # -------------------------------
14
+ # Oracle Main Function
15
  # -------------------------------
16
  @spaces.GPU
17
  def oracle_prophecy(user_text, user_img, user_audio, user_pdf):
18
  prophecy = ""
19
 
20
+ # Text
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
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
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
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 += "📑 PDF: ⚠️ No readable text found.\n\n"
65
 
66
  if prophecy.strip() == "":
67
+ prophecy = "⚠️ Please provide text, an image, a voice file, or a PDF."
68
 
69
  return prophecy
70
 
71
  # -------------------------------
72
+ # Gradio UI (Aligned Card Style like Beat‑Break)
73
  # -------------------------------
74
  with gr.Blocks(css="""
75
+ /* Background and Base */
76
  body {
77
  background: linear-gradient(135deg, #667eea, #764ba2);
78
  font-family: 'Trebuchet MS', sans-serif;
 
 
79
  margin: 0;
80
  padding: 0;
81
+ color: #fff;
82
+ text-align: center;
83
  }
84
 
85
+ /* Container to center, shrink width */
86
+ .container {
87
+ max-width: 900px;
88
+ margin: 0 auto;
89
+ padding: 20px;
90
+ }
91
+
92
+ /* Title + Subtitle */
93
  #title {
94
  font-size: 3em !important;
95
  color: #FFD700 !important;
96
+ text-shadow: 2px 2px 8px #000;
97
+ margin-bottom: 10px;
98
  }
 
 
99
  #subtitle {
100
  font-size: 1.5em !important;
101
  color: #E0FFFF !important;
102
  margin-bottom: 30px;
103
  }
104
 
105
+ /* Inputs */
106
  label {
107
+ font-size: 1.2em !important;
108
  color: #fff !important;
109
  }
110
  textarea, input, .gr-textbox {
111
  font-size: 1.2em !important;
112
  }
113
+ audio, .gr-file, .gr-image {
114
+ margin-bottom: 20px;
115
+ }
116
 
117
+ /* Button */
118
  button {
119
+ font-size: 1.3em !important;
120
  padding: 12px 28px !important;
121
  border-radius: 12px !important;
122
  background: linear-gradient(90deg, #ff8a00, #e52e71) !important;
123
  color: #fff !important;
124
  font-weight: bold !important;
125
  border: none !important;
126
+ margin-top: 20px;
127
+ }
128
+ button:hover {
129
+ opacity: 0.9;
130
+ box-shadow: 0 0 20px #FFD700;
131
  }
132
 
133
  /* Result Box */
134
  .result-box {
135
+ background: #fff;
136
+ border-radius: 20px;
137
+ padding: 25px;
138
+ margin: 30px auto;
139
+ font-size: 1.4em;
140
+ color: #222;
141
+ box-shadow: 0px 6px 20px rgba(0,0,0,0.4);
142
+ text-align: left;
143
+ white-space: pre-line;
144
  }
145
  """) as demo:
146
 
147
+ with gr.Column(elem_classes="container"):
148
+ gr.HTML("<div id='title'>🔮 Oracle of Truth 🔮</div>")
149
+ gr.HTML("<div id='subtitle'>✨ Offer Text · Image · Voice File · PDF ✨</div>")
150
 
151
+ txt_in = gr.Textbox(lines=4, label="📜 Text Offering")
152
+ img_in = gr.Image(type="filepath", label="🖼️ Image Offering")
153
+ # VOICE: file upload only
154
+ aud_in = gr.File(file_types=[".wav", ".mp3"], label="🔊 Voice File Offering")
155
+ pdf_in = gr.File(file_types=[".pdf"], label="📑 PDF Offering")
156
 
157
+ btn = gr.Button("✨ Reveal Prophecy")
158
+ output = gr.HTML(elem_classes="result-box")
159
 
160
+ btn.click(oracle_prophecy, [txt_in, img_in, aud_in, pdf_in], output)
161
 
162
  demo.launch()