Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,14 @@ import requests, json, pathlib, mimetypes
|
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
API_ENDPOINT = "https://preprintwatch.com/wp-json/pw-kgx3/v1/submit"
|
| 10 |
-
API_KEY
|
| 11 |
|
| 12 |
|
| 13 |
# === CORE LOGIC ===
|
| 14 |
def call_kgx3(title, email, pdf_file, agreement):
|
| 15 |
"""Send uploaded PDF to the shared KGX3 endpoint on PreprintWatch if disclaimer accepted."""
|
| 16 |
if not agreement:
|
| 17 |
-
return "You must accept the disclaimer before running KGX3.", ""
|
| 18 |
if not pdf_file:
|
| 19 |
return "Please select a PDF file.", ""
|
| 20 |
pdf_path = pdf_file.name
|
|
@@ -23,8 +23,8 @@ def call_kgx3(title, email, pdf_file, agreement):
|
|
| 23 |
|
| 24 |
# Build the Hugging Face Space file URL
|
| 25 |
space_root = gr.get_current_space() or "https://your-space-name.hf.space"
|
| 26 |
-
file_name
|
| 27 |
-
file_url = f"{
|
| 28 |
|
| 29 |
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
|
| 30 |
payload = {
|
|
@@ -36,174 +36,103 @@ def call_kgx3(title, email, pdf_file, agreement):
|
|
| 36 |
|
| 37 |
try:
|
| 38 |
resp = requests.post(API_ENDPOINT, headers=headers, json=payload, timeout=180)
|
| 39 |
-
body = resp.text
|
| 40 |
try:
|
| 41 |
body = json.dumps(resp.json(), indent=2, ensure_ascii=False)
|
| 42 |
except Exception:
|
| 43 |
-
|
| 44 |
return body, file_url
|
| 45 |
except requests.RequestException as e:
|
| 46 |
return f"Request error: {e}", file_url
|
| 47 |
|
| 48 |
|
| 49 |
-
# === STYLE (
|
| 50 |
FUTURE_CSS = """
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
font-family: 'Courier New', monospace !important;
|
| 54 |
-
color: #00ff99 !important;
|
| 55 |
-
box-sizing: border-box;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
body, .gradio-container {
|
| 59 |
-
background-color: #000 !important;
|
| 60 |
-
color: #00ff99 !important;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/* === HEADINGS & TEXT === */
|
| 64 |
h1, h2, h3, label, .label {
|
| 65 |
-
color: #00ff99 !important;
|
| 66 |
-
|
| 67 |
-
text-transform: uppercase;
|
| 68 |
-
letter-spacing: 0.5px;
|
| 69 |
-
margin-bottom: 8px;
|
| 70 |
-
border-bottom: 1px solid #00ff99;
|
| 71 |
-
padding-bottom: 4px;
|
| 72 |
}
|
| 73 |
p, span, small, strong { color: #00ff99 !important; }
|
| 74 |
::placeholder { color: #00ff99 !important; opacity: 0.7; }
|
| 75 |
|
| 76 |
-
/* === PANELS & CONTAINERS === */
|
| 77 |
.gr-box, .gr-panel {
|
| 78 |
-
background: #000 !important;
|
| 79 |
-
border:
|
| 80 |
-
border-radius: 8px;
|
| 81 |
-
padding: 12px;
|
| 82 |
}
|
| 83 |
-
|
| 84 |
-
/* === INPUTS & TEXTAREAS === */
|
| 85 |
input, textarea, select {
|
| 86 |
-
background: #000 !important;
|
| 87 |
-
border:
|
| 88 |
-
color: #00ff99 !important;
|
| 89 |
-
border-radius: 4px;
|
| 90 |
-
padding: 8px !important;
|
| 91 |
}
|
| 92 |
input:focus, textarea:focus {
|
| 93 |
-
outline: none !important;
|
| 94 |
-
border: 1px solid #00ffcc !important;
|
| 95 |
-
background: #001a10 !important;
|
| 96 |
}
|
| 97 |
-
|
| 98 |
-
/* === FILE UPLOAD BOX === */
|
| 99 |
.upload-box, .file-preview, .wrap-inner {
|
| 100 |
-
background: #000 !important;
|
| 101 |
-
|
| 102 |
-
border-radius: 6px !important;
|
| 103 |
-
padding: 10px !important;
|
| 104 |
-
display: flex !important;
|
| 105 |
-
align-items: center !important;
|
| 106 |
-
justify-content: center !important;
|
| 107 |
transition: all 0.2s ease-in-out;
|
| 108 |
}
|
| 109 |
-
.upload-box:hover {
|
| 110 |
-
border-color: #00ffaa !important;
|
| 111 |
-
background: #001a10 !important;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/* === BUTTONS === */
|
| 115 |
button {
|
| 116 |
-
background: #000 !important;
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
border-radius: 4px;
|
| 120 |
-
text-transform: uppercase;
|
| 121 |
-
font-weight: 700;
|
| 122 |
-
padding: 8px 16px !important;
|
| 123 |
-
letter-spacing: 0.5px;
|
| 124 |
-
transition: all 0.15s ease-in-out;
|
| 125 |
-
}
|
| 126 |
-
button:hover {
|
| 127 |
-
background: #00ff99 !important;
|
| 128 |
-
color: #000 !important;
|
| 129 |
}
|
| 130 |
-
|
| 131 |
-
/* === CODE / OUTPUT BOX === */
|
| 132 |
pre, code, .cm-editor, .cm-content, .cm-line {
|
| 133 |
-
background: #000 !important;
|
| 134 |
-
|
| 135 |
-
border: 1px solid #00ff99 !important;
|
| 136 |
-
border-radius: 6px;
|
| 137 |
-
padding: 10px !important;
|
| 138 |
-
font-size: 0.9rem;
|
| 139 |
}
|
| 140 |
-
|
| 141 |
-
/* === CHECKBOX === */
|
| 142 |
-
input[type=checkbox] {
|
| 143 |
-
accent-color: #00ff99 !important;
|
| 144 |
-
transform: scale(1.1);
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/* === SCROLLBARS === */
|
| 148 |
::-webkit-scrollbar { width: 8px; background: #000; }
|
| 149 |
::-webkit-scrollbar-thumb { background: #00ff99; border-radius: 4px; }
|
| 150 |
-
|
| 151 |
-
/* === FOOTER TEXT === */
|
| 152 |
-
footer, .footer, small {
|
| 153 |
-
color: #00ff99 !important;
|
| 154 |
-
opacity: 0.8;
|
| 155 |
-
text-align: center;
|
| 156 |
-
letter-spacing: 0.4px;
|
| 157 |
-
}
|
| 158 |
"""
|
| 159 |
|
| 160 |
|
| 161 |
# === BUILD APP ===
|
| 162 |
with gr.Blocks(css=FUTURE_CSS, title="Shared KGX3 API Endpoint") as demo:
|
| 163 |
-
gr.Markdown(
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
"""
|
| 169 |
-
)
|
| 170 |
|
| 171 |
# --- Disclaimer Section ---
|
| 172 |
-
gr.Markdown(
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
"""
|
| 181 |
-
)
|
| 182 |
|
| 183 |
agreement = gr.Checkbox(
|
| 184 |
label="I have read and accept full responsibility and accountability for the files I upload.",
|
| 185 |
value=False
|
| 186 |
)
|
| 187 |
|
| 188 |
-
# --- Main
|
| 189 |
with gr.Row():
|
| 190 |
with gr.Column(scale=1):
|
| 191 |
title_box = gr.Textbox(label="Preprint Title", placeholder="Enter or paste the paper title")
|
| 192 |
email_box = gr.Textbox(label="Email (optional)", placeholder="you@example.com")
|
| 193 |
-
file_box
|
| 194 |
-
run_btn
|
| 195 |
with gr.Column(scale=1):
|
| 196 |
output_json = gr.Code(label="KGX3 Response", language="json")
|
| 197 |
-
output_url
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
gr.Markdown(
|
| 204 |
-
"<small>Built on Gradio • Hosted on Hugging Face Spaces • "
|
| 205 |
-
"Thomas Kuhn Foundation © 2025</small>"
|
| 206 |
)
|
| 207 |
|
| 208 |
-
|
| 209 |
demo.launch()
|
|
|
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
API_ENDPOINT = "https://preprintwatch.com/wp-json/pw-kgx3/v1/submit"
|
| 10 |
+
API_KEY = "sk-X1zY9wS3-vU4tQ0-rOjH5gK2fE7mN6"
|
| 11 |
|
| 12 |
|
| 13 |
# === CORE LOGIC ===
|
| 14 |
def call_kgx3(title, email, pdf_file, agreement):
|
| 15 |
"""Send uploaded PDF to the shared KGX3 endpoint on PreprintWatch if disclaimer accepted."""
|
| 16 |
if not agreement:
|
| 17 |
+
return "⚠️ You must accept the disclaimer before running KGX3.", ""
|
| 18 |
if not pdf_file:
|
| 19 |
return "Please select a PDF file.", ""
|
| 20 |
pdf_path = pdf_file.name
|
|
|
|
| 23 |
|
| 24 |
# Build the Hugging Face Space file URL
|
| 25 |
space_root = gr.get_current_space() or "https://your-space-name.hf.space"
|
| 26 |
+
file_name = pathlib.Path(pdf_path).name
|
| 27 |
+
file_url = f"{space_root}/file={file_name}"
|
| 28 |
|
| 29 |
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
|
| 30 |
payload = {
|
|
|
|
| 36 |
|
| 37 |
try:
|
| 38 |
resp = requests.post(API_ENDPOINT, headers=headers, json=payload, timeout=180)
|
|
|
|
| 39 |
try:
|
| 40 |
body = json.dumps(resp.json(), indent=2, ensure_ascii=False)
|
| 41 |
except Exception:
|
| 42 |
+
body = resp.text
|
| 43 |
return body, file_url
|
| 44 |
except requests.RequestException as e:
|
| 45 |
return f"Request error: {e}", file_url
|
| 46 |
|
| 47 |
|
| 48 |
+
# === STYLE (high-contrast futuristic) ===
|
| 49 |
FUTURE_CSS = """
|
| 50 |
+
* { font-family: 'Courier New', monospace !important; color: #00ff99 !important; box-sizing: border-box; }
|
| 51 |
+
body, .gradio-container { background-color: #000 !important; color: #00ff99 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
h1, h2, h3, label, .label {
|
| 53 |
+
color: #00ff99 !important; font-weight: 700 !important; text-transform: uppercase;
|
| 54 |
+
letter-spacing: 0.5px; margin-bottom: 8px; border-bottom: 1px solid #00ff99; padding-bottom: 4px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
p, span, small, strong { color: #00ff99 !important; }
|
| 57 |
::placeholder { color: #00ff99 !important; opacity: 0.7; }
|
| 58 |
|
|
|
|
| 59 |
.gr-box, .gr-panel {
|
| 60 |
+
background: #000 !important; border: 1px solid #00ff99 !important;
|
| 61 |
+
border-radius: 8px; padding: 12px;
|
|
|
|
|
|
|
| 62 |
}
|
|
|
|
|
|
|
| 63 |
input, textarea, select {
|
| 64 |
+
background: #000 !important; border: 1px solid #00ff99 !important;
|
| 65 |
+
color: #00ff99 !important; border-radius: 4px; padding: 8px !important;
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
input:focus, textarea:focus {
|
| 68 |
+
outline: none !important; border: 1px solid #00ffcc !important; background: #001a10 !important;
|
|
|
|
|
|
|
| 69 |
}
|
|
|
|
|
|
|
| 70 |
.upload-box, .file-preview, .wrap-inner {
|
| 71 |
+
background: #000 !important; border: 2px solid #00ff99 !important; border-radius: 6px !important;
|
| 72 |
+
padding: 10px !important; display: flex !important; align-items: center !important; justify-content: center !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
transition: all 0.2s ease-in-out;
|
| 74 |
}
|
| 75 |
+
.upload-box:hover { border-color: #00ffaa !important; background: #001a10 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
button {
|
| 77 |
+
background: #000 !important; color: #00ff99 !important; border: 2px solid #00ff99 !important;
|
| 78 |
+
border-radius: 4px; text-transform: uppercase; font-weight: 700; padding: 8px 16px !important;
|
| 79 |
+
letter-spacing: 0.5px; transition: all 0.15s ease-in-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
+
button:hover { background: #00ff99 !important; color: #000 !important; }
|
|
|
|
| 82 |
pre, code, .cm-editor, .cm-content, .cm-line {
|
| 83 |
+
background: #000 !important; color: #00ff99 !important; border: 1px solid #00ff99 !important;
|
| 84 |
+
border-radius: 6px; padding: 10px !important; font-size: 0.9rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
+
input[type=checkbox] { accent-color: #00ff99 !important; transform: scale(1.2); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
::-webkit-scrollbar { width: 8px; background: #000; }
|
| 88 |
::-webkit-scrollbar-thumb { background: #00ff99; border-radius: 4px; }
|
| 89 |
+
footer, .footer, small { color: #00ff99 !important; opacity: 0.8; text-align: center; letter-spacing: 0.4px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
|
| 93 |
# === BUILD APP ===
|
| 94 |
with gr.Blocks(css=FUTURE_CSS, title="Shared KGX3 API Endpoint") as demo:
|
| 95 |
+
gr.Markdown("""
|
| 96 |
+
# 🧠 **KGX3 Engine**
|
| 97 |
+
Upload a scientific preprint PDF.
|
| 98 |
+
The app sends it to the **PreprintWatch KGX3** API for automated paradigm-cycle analysis.
|
| 99 |
+
""")
|
|
|
|
|
|
|
| 100 |
|
| 101 |
# --- Disclaimer Section ---
|
| 102 |
+
gr.Markdown("""
|
| 103 |
+
### ⚠️ Disclaimer
|
| 104 |
+
By using this interface, you confirm that:
|
| 105 |
+
- You are solely responsible and accountable for the files you upload.
|
| 106 |
+
- All uploaded files are automatically deleted within **24 hours**.
|
| 107 |
+
- System logs of KGX3 activity are retained securely for **up to 60 days** for service auditing.
|
| 108 |
+
- You must ensure that any material you upload is lawful, non-confidential, and free of third-party rights restrictions.
|
| 109 |
+
""")
|
|
|
|
|
|
|
| 110 |
|
| 111 |
agreement = gr.Checkbox(
|
| 112 |
label="I have read and accept full responsibility and accountability for the files I upload.",
|
| 113 |
value=False
|
| 114 |
)
|
| 115 |
|
| 116 |
+
# --- Main layout ---
|
| 117 |
with gr.Row():
|
| 118 |
with gr.Column(scale=1):
|
| 119 |
title_box = gr.Textbox(label="Preprint Title", placeholder="Enter or paste the paper title")
|
| 120 |
email_box = gr.Textbox(label="Email (optional)", placeholder="you@example.com")
|
| 121 |
+
file_box = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
|
| 122 |
+
run_btn = gr.Button("Run KGX3", variant="primary")
|
| 123 |
with gr.Column(scale=1):
|
| 124 |
output_json = gr.Code(label="KGX3 Response", language="json")
|
| 125 |
+
output_url = gr.Textbox(label="PDF Link Used", interactive=False)
|
| 126 |
|
| 127 |
+
# --- Button logic (checkbox included) ---
|
| 128 |
+
run_btn.click(
|
| 129 |
+
call_kgx3,
|
| 130 |
+
inputs=[title_box, email_box, file_box, agreement],
|
| 131 |
+
outputs=[output_json, output_url]
|
| 132 |
+
)
|
| 133 |
|
| 134 |
gr.Markdown(
|
| 135 |
+
"<small>Built on Gradio • Hosted on Hugging Face Spaces • Thomas Kuhn Foundation © 2025</small>"
|
|
|
|
| 136 |
)
|
| 137 |
|
|
|
|
| 138 |
demo.launch()
|