Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,19 +3,13 @@ import spaces
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# -------------------------------
|
| 6 |
-
# Load
|
| 7 |
# -------------------------------
|
| 8 |
-
|
| 9 |
-
# Text AI detector
|
| 10 |
text_detector = pipeline("text-classification", model="roberta-base-openai-detector")
|
| 11 |
|
| 12 |
-
# Image AI detector
|
| 13 |
-
image_detector = pipeline("image-classification", model="oripress/ai-image-detector")
|
| 14 |
-
|
| 15 |
# -------------------------------
|
| 16 |
-
#
|
| 17 |
# -------------------------------
|
| 18 |
-
|
| 19 |
@spaces.GPU
|
| 20 |
def detect_text(user_text: str):
|
| 21 |
if not user_text.strip():
|
|
@@ -28,55 +22,38 @@ def detect_text(user_text: str):
|
|
| 28 |
else:
|
| 29 |
return f"☀️ Oracle’s Vision: {score}% chance this was written by a mortal hand 🧑💻"
|
| 30 |
|
| 31 |
-
@spaces.GPU
|
| 32 |
-
def detect_image(user_img):
|
| 33 |
-
if user_img is None:
|
| 34 |
-
return "🖼️ Please upload an image for the Oracle to divine."
|
| 35 |
-
result = image_detector(user_img)
|
| 36 |
-
label = result[0]['label']
|
| 37 |
-
score = round(result[0]['score'] * 100, 2)
|
| 38 |
-
return f"🌠 Oracle’s Gaze: {score}% chance this is {label}."
|
| 39 |
-
|
| 40 |
# -------------------------------
|
| 41 |
# Gradio UI
|
| 42 |
# -------------------------------
|
| 43 |
with gr.Blocks(css="""
|
| 44 |
body {
|
| 45 |
-
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
|
| 46 |
font-family: Trebuchet MS, sans-serif;
|
| 47 |
color: white;
|
| 48 |
}
|
| 49 |
-
h1
|
| 50 |
""") as demo:
|
| 51 |
|
| 52 |
gr.HTML("<h1 style='text-align:center;'>🔮 Oracle of Truth 🔮</h1>")
|
| 53 |
gr.Markdown("""
|
| 54 |
Welcome to the **Chamber of Truth** ✨.
|
| 55 |
-
Offer your **text**
|
| 56 |
and it will divine whether it was born of **human hands** ☀️
|
| 57 |
or conjured by **AI sorcery** 🤖🌌.
|
| 58 |
""")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
btn_txt.click(detect_text, inputs=txt_in, outputs=txt_out)
|
| 65 |
-
|
| 66 |
-
with gr.Tab("🖼️ Image Divination"):
|
| 67 |
-
img_in = gr.Image(type="filepath", label="Upload an Image")
|
| 68 |
-
btn_img = gr.Button("🔍 Ask the Oracle")
|
| 69 |
-
img_out = gr.Textbox(label="Oracle's Verdict", lines=2)
|
| 70 |
-
btn_img.click(detect_image, inputs=img_in, outputs=img_out)
|
| 71 |
|
| 72 |
# Preloaded examples
|
| 73 |
gr.Examples(
|
| 74 |
examples=[
|
| 75 |
-
["Once upon a time in a galaxy far away
|
| 76 |
["In this paper, we analyze the performance of Transformer models on natural language inference tasks."]
|
| 77 |
],
|
| 78 |
-
inputs=txt_in
|
| 79 |
-
label="Try sample texts"
|
| 80 |
)
|
| 81 |
|
| 82 |
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 |
+
# Function for Oracle of Truth
|
| 12 |
# -------------------------------
|
|
|
|
| 13 |
@spaces.GPU
|
| 14 |
def detect_text(user_text: str):
|
| 15 |
if not user_text.strip():
|
|
|
|
| 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()
|