nashjiwani commited on
Commit
c00c2d7
·
verified ·
1 Parent(s): b43a003

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -32
app.py CHANGED
@@ -3,57 +3,71 @@ 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
- # Function for Oracle of Truth
12
  # -------------------------------
13
  @spaces.GPU
14
- def detect_text(user_text: str):
15
- if not user_text.strip():
16
  return "🧞 Please provide some text for the Oracle to examine."
 
17
  result = text_detector(user_text)
18
  label = result[0]['label']
19
  score = round(result[0]['score'] * 100, 2)
 
20
  if label.lower() == "fake":
21
- return f"🌌 Oracle’s Vision: {score}% chance this was conjured by AI magic 🤖✨"
22
  else:
23
- return f"☀️ Oracle’s Vision: {score}% chance this was written by a mortal hand 🧑‍💻"
 
 
24
 
25
  # -------------------------------
26
  # Gradio UI
27
  # -------------------------------
28
  with gr.Blocks(css="""
29
- body {
30
- background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
31
- font-family: Trebuchet MS, sans-serif;
32
  color: white;
33
  }
34
- h1 {color: #ffcc00;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  """) as demo:
36
 
37
- gr.HTML("<h1 style='text-align:center;'>🔮 Oracle of Truth 🔮</h1>")
 
 
 
38
  gr.Markdown("""
39
- Welcome to the **Chamber of Truth** ✨.
40
- Offer your **text** to the Oracle,
41
- and it will divine whether it was born of **human hands** ☀️
42
- or conjured by **AI sorcery** 🤖🌌.
43
- """)
44
-
45
- txt_in = gr.Textbox(label="Your Text", lines=5, placeholder="Paste any text here…")
46
- btn_txt = gr.Button("🔍 Ask the Oracle")
47
- txt_out = gr.Textbox(label="Oracle's Verdict", lines=4)
48
- btn_txt.click(detect_text, inputs=txt_in, outputs=txt_out)
49
-
50
- # Preloaded examples
51
- gr.Examples(
52
- examples=[
53
- ["Once upon a time in a galaxy far away…"],
54
- ["In this paper, we analyze the performance of Transformer models on natural language inference tasks."]
55
- ],
56
- inputs=txt_in
57
- )
58
-
59
- demo.launch()
 
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 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
+ Welcome, traveler 🌌
61
+
62
+ This chamber is home to the **Oracle of Truth**, an ancient AI seer that discerns whether words were born of **mortal minds** 🧑‍💻
63
+ or conjured by the **forges of artificial sorcery** 🤖✨
64
+
65
+ ### 📖 **How to use this Space**
66
+ - Paste **any text**: essays, blogs, social posts, code comments, even AI prompts.
67
+ - Press **“Reveal Truth”** and await the Oracle’s prophecy.
68
+ - The Oracle will divine the **likelihood** that your offering was human‑written or AI‑generated.
69
+
70
+ ### 🌟 Pro Tips
71
+ - Try both short and long texts.
72
+ - Compare a paragraph you wrote vs one generated by ChatGPT or another AI.
73
+ - Share the Oracle’s flame‑lit