Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,188 +0,0 @@
|
|
| 1 |
-
# %%capture
|
| 2 |
-
!pip -q install gradio requests tqdm
|
| 3 |
-
|
| 4 |
-
# %%
|
| 5 |
-
import gradio as gr, requests, mimetypes, pathlib, json, time, tempfile, os
|
| 6 |
-
from tqdm import tqdm
|
| 7 |
-
|
| 8 |
-
API_ENDPOINT = "https://preprintwatch.com/wp-json/pw-kgx3/v1/submit"
|
| 9 |
-
API_KEY = "sk-X1zY9wS3-vU4tQ0-rOjH5gK2fE7mN6"
|
| 10 |
-
|
| 11 |
-
def _upload_temp(pdf_path):
|
| 12 |
-
"""Uploads PDF to file.io with visible progress."""
|
| 13 |
-
file_size = os.path.getsize(pdf_path)
|
| 14 |
-
with open(pdf_path, "rb") as f:
|
| 15 |
-
with tqdm(total=file_size, unit="B", unit_scale=True, desc="Uploading", colour="green") as pbar:
|
| 16 |
-
def read_in_chunks(file_object, chunk_size=1024):
|
| 17 |
-
while True:
|
| 18 |
-
data = file_object.read(chunk_size)
|
| 19 |
-
if not data:
|
| 20 |
-
break
|
| 21 |
-
pbar.update(len(data))
|
| 22 |
-
yield data
|
| 23 |
-
r = requests.post("https://file.io", files={"file": (os.path.basename(pdf_path), read_in_chunks(f))})
|
| 24 |
-
data = r.json()
|
| 25 |
-
if not data.get("success"):
|
| 26 |
-
raise RuntimeError("Upload failed.")
|
| 27 |
-
return data["link"]
|
| 28 |
-
|
| 29 |
-
def call_kgx3(title, email, pdf_file):
|
| 30 |
-
if not pdf_file:
|
| 31 |
-
return "⚠️ Please select a PDF.", ""
|
| 32 |
-
pdf_path = pdf_file.name
|
| 33 |
-
mime, _ = mimetypes.guess_type(pdf_path)
|
| 34 |
-
if (mime or "").lower() != "application/pdf" and not pdf_path.lower().endswith(".pdf"):
|
| 35 |
-
return "Only PDF files are accepted.", ""
|
| 36 |
-
|
| 37 |
-
try:
|
| 38 |
-
url = _upload_temp(pdf_path)
|
| 39 |
-
except Exception as e:
|
| 40 |
-
return f"Upload error: {e}", ""
|
| 41 |
-
|
| 42 |
-
payload = {"title": title or pathlib.Path(pdf_path).stem, "pdf_url": url}
|
| 43 |
-
if email:
|
| 44 |
-
payload["email"] = email
|
| 45 |
-
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
|
| 46 |
-
|
| 47 |
-
r = requests.post(API_ENDPOINT, headers=headers, json=payload, timeout=180)
|
| 48 |
-
try:
|
| 49 |
-
resp = json.dumps(r.json(), indent=2, ensure_ascii=False)
|
| 50 |
-
except Exception:
|
| 51 |
-
resp = r.text
|
| 52 |
-
return resp, url
|
| 53 |
-
|
| 54 |
-
# Matrix neon CSS
|
| 55 |
-
MATRIX_CSS = """
|
| 56 |
-
* { font-family: 'Courier New', monospace !important; }
|
| 57 |
-
.gradio-container { background-color: #000 !important; color: #00ff99 !important; }
|
| 58 |
-
label, .label, .svelte-1ipelgc { color: #00ff99 !important; }
|
| 59 |
-
textarea, input, .upload-box, .file-preview, .wrap-inner, .scroll-hide {
|
| 60 |
-
background-color: #000 !important; color: #00ff99 !important; border: 1px solid #00ff99 !important;
|
| 61 |
-
}
|
| 62 |
-
button {
|
| 63 |
-
background-color: #000 !important; border: 1px solid #00ff99 !important;
|
| 64 |
-
color: #00ff99 !important; font-weight: bold;
|
| 65 |
-
box-shadow: 0 0 8px #00ff99; transition: 0.2s;
|
| 66 |
-
}
|
| 67 |
-
button:hover { background-color: #00ff99 !important; color: #000 !important; }
|
| 68 |
-
progress::-webkit-progress-value { background: #00ff99; }
|
| 69 |
-
progress::-webkit-progress-bar { background: #002a1a; }
|
| 70 |
-
.matrix-border { border: 2px solid #00ff99; box-shadow: 0 0 12px #00ff99 inset; border-radius: 10px; padding: 15px; }
|
| 71 |
-
.matrix-bg {
|
| 72 |
-
background: radial-gradient(circle at 50% 50%, rgba(0,255,128,0.15), transparent 60%),
|
| 73 |
-
repeating-linear-gradient(180deg, rgba(0,255,128,0.1) 2px, transparent 3px);
|
| 74 |
-
animation: matrix-move 3s linear infinite;
|
| 75 |
-
}
|
| 76 |
-
@keyframes matrix-move { from { background-position-y: 0; } to { background-position-y: 100px; } }
|
| 77 |
-
"""
|
| 78 |
-
|
| 79 |
-
with gr.Blocks(css=MATRIX_CSS, title="KGX3 Matrix Console") as app:
|
| 80 |
-
gr.HTML('<div class="matrix-bg" style="position:fixed;inset:0;z-index:-1;"></div>')
|
| 81 |
-
gr.Markdown("## 🟩 KGX3 Matrix Console\nNeon interface for PreprintWatch KGX3 endpoint")
|
| 82 |
-
with gr.Row():
|
| 83 |
-
with gr.Column(scale=1, elem_classes=["matrix-border"]):
|
| 84 |
-
title = gr.Textbox(label="Preprint Title", placeholder="Enter title")
|
| 85 |
-
email = gr.Textbox(label="Email (optional)", placeholder="you@example.com")
|
| 86 |
-
pdf = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
|
| 87 |
-
run = gr.Button("▶ RUN KGX3", variant="primary")
|
| 88 |
-
gr.Markdown("*File uploads use a temporary host (file.io). Not for confidential documents.*")
|
| 89 |
-
with gr.Column(scale=1, elem_classes=["matrix-border"]):
|
| 90 |
-
out_json = gr.Code(label="KGX3 Response", language="json")
|
| 91 |
-
out_url = gr.Textbox(label="Public PDF URL", interactive=False)
|
| 92 |
-
run.click(call_kgx3, [title, email, pdf], [out_json, out_url])
|
| 93 |
-
|
| 94 |
-
app.launch(share=True)
|
| 95 |
-
# %%capture
|
| 96 |
-
!pip -q install gradio requests tqdm
|
| 97 |
-
|
| 98 |
-
# %%
|
| 99 |
-
import gradio as gr, requests, mimetypes, pathlib, json, time, tempfile, os
|
| 100 |
-
from tqdm import tqdm
|
| 101 |
-
|
| 102 |
-
API_ENDPOINT = "https://preprintwatch.com/wp-json/pw-kgx3/v1/submit"
|
| 103 |
-
API_KEY = "sk-X1zY9wS3-vU4tQ0-rOjH5gK2fE7mN6"
|
| 104 |
-
|
| 105 |
-
def _upload_temp(pdf_path):
|
| 106 |
-
"""Uploads PDF to file.io with visible progress."""
|
| 107 |
-
file_size = os.path.getsize(pdf_path)
|
| 108 |
-
with open(pdf_path, "rb") as f:
|
| 109 |
-
with tqdm(total=file_size, unit="B", unit_scale=True, desc="Uploading", colour="green") as pbar:
|
| 110 |
-
def read_in_chunks(file_object, chunk_size=1024):
|
| 111 |
-
while True:
|
| 112 |
-
data = file_object.read(chunk_size)
|
| 113 |
-
if not data:
|
| 114 |
-
break
|
| 115 |
-
pbar.update(len(data))
|
| 116 |
-
yield data
|
| 117 |
-
r = requests.post("https://file.io", files={"file": (os.path.basename(pdf_path), read_in_chunks(f))})
|
| 118 |
-
data = r.json()
|
| 119 |
-
if not data.get("success"):
|
| 120 |
-
raise RuntimeError("Upload failed.")
|
| 121 |
-
return data["link"]
|
| 122 |
-
|
| 123 |
-
def call_kgx3(title, email, pdf_file):
|
| 124 |
-
if not pdf_file:
|
| 125 |
-
return "⚠️ Please select a PDF.", ""
|
| 126 |
-
pdf_path = pdf_file.name
|
| 127 |
-
mime, _ = mimetypes.guess_type(pdf_path)
|
| 128 |
-
if (mime or "").lower() != "application/pdf" and not pdf_path.lower().endswith(".pdf"):
|
| 129 |
-
return "Only PDF files are accepted.", ""
|
| 130 |
-
|
| 131 |
-
try:
|
| 132 |
-
url = _upload_temp(pdf_path)
|
| 133 |
-
except Exception as e:
|
| 134 |
-
return f"Upload error: {e}", ""
|
| 135 |
-
|
| 136 |
-
payload = {"title": title or pathlib.Path(pdf_path).stem, "pdf_url": url}
|
| 137 |
-
if email:
|
| 138 |
-
payload["email"] = email
|
| 139 |
-
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
|
| 140 |
-
|
| 141 |
-
r = requests.post(API_ENDPOINT, headers=headers, json=payload, timeout=180)
|
| 142 |
-
try:
|
| 143 |
-
resp = json.dumps(r.json(), indent=2, ensure_ascii=False)
|
| 144 |
-
except Exception:
|
| 145 |
-
resp = r.text
|
| 146 |
-
return resp, url
|
| 147 |
-
|
| 148 |
-
# Matrix neon CSS
|
| 149 |
-
MATRIX_CSS = """
|
| 150 |
-
* { font-family: 'Courier New', monospace !important; }
|
| 151 |
-
.gradio-container { background-color: #000 !important; color: #00ff99 !important; }
|
| 152 |
-
label, .label, .svelte-1ipelgc { color: #00ff99 !important; }
|
| 153 |
-
textarea, input, .upload-box, .file-preview, .wrap-inner, .scroll-hide {
|
| 154 |
-
background-color: #000 !important; color: #00ff99 !important; border: 1px solid #00ff99 !important;
|
| 155 |
-
}
|
| 156 |
-
button {
|
| 157 |
-
background-color: #000 !important; border: 1px solid #00ff99 !important;
|
| 158 |
-
color: #00ff99 !important; font-weight: bold;
|
| 159 |
-
box-shadow: 0 0 8px #00ff99; transition: 0.2s;
|
| 160 |
-
}
|
| 161 |
-
button:hover { background-color: #00ff99 !important; color: #000 !important; }
|
| 162 |
-
progress::-webkit-progress-value { background: #00ff99; }
|
| 163 |
-
progress::-webkit-progress-bar { background: #002a1a; }
|
| 164 |
-
.matrix-border { border: 2px solid #00ff99; box-shadow: 0 0 12px #00ff99 inset; border-radius: 10px; padding: 15px; }
|
| 165 |
-
.matrix-bg {
|
| 166 |
-
background: radial-gradient(circle at 50% 50%, rgba(0,255,128,0.15), transparent 60%),
|
| 167 |
-
repeating-linear-gradient(180deg, rgba(0,255,128,0.1) 2px, transparent 3px);
|
| 168 |
-
animation: matrix-move 3s linear infinite;
|
| 169 |
-
}
|
| 170 |
-
@keyframes matrix-move { from { background-position-y: 0; } to { background-position-y: 100px; } }
|
| 171 |
-
"""
|
| 172 |
-
|
| 173 |
-
with gr.Blocks(css=MATRIX_CSS, title="KGX3 Console") as app:
|
| 174 |
-
gr.HTML('<div class="matrix-bg" style="position:fixed;inset:0;z-index:-1;"></div>')
|
| 175 |
-
gr.Markdown("## 🟩 KGX3 Matrix Console\nNeon interface for PreprintWatch KGX3 endpoint")
|
| 176 |
-
with gr.Row():
|
| 177 |
-
with gr.Column(scale=1, elem_classes=["matrix-border"]):
|
| 178 |
-
title = gr.Textbox(label="Preprint Title", placeholder="Enter title")
|
| 179 |
-
email = gr.Textbox(label="Email (optional)", placeholder="you@example.com")
|
| 180 |
-
pdf = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
|
| 181 |
-
run = gr.Button("▶ RUN KGX3", variant="primary")
|
| 182 |
-
gr.Markdown("*File uploads use a temporary host (file.io). Not for confidential documents.*")
|
| 183 |
-
with gr.Column(scale=1, elem_classes=["matrix-border"]):
|
| 184 |
-
out_json = gr.Code(label="KGX3 Response", language="json")
|
| 185 |
-
out_url = gr.Textbox(label="Public PDF URL", interactive=False)
|
| 186 |
-
run.click(call_kgx3, [title, email, pdf], [out_json, out_url])
|
| 187 |
-
|
| 188 |
-
app.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|