K1SysAdmin commited on
Commit
ffc3f41
·
verified ·
1 Parent(s): 9896c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -42
app.py CHANGED
@@ -1,27 +1,27 @@
1
  """
2
- Shared KGX3 API Endpoint on PreprintWatch (Demo).
3
- User uploads a PDF, builds the proper public link, and sends it to the PreprintWatch KGX3 endpoint.
4
  """
5
 
6
  import gradio as gr
7
  import requests, json, pathlib, mimetypes
8
 
9
-
10
  # === CONFIGURATION ===
11
  API_ENDPOINT = "https://preprintwatch.com/wp-json/pw-kgx3/v1/submit"
12
  API_KEY = "sk-X1zY9wS3-vU4tQ0-rOjH5gK2fE7mN6"
13
 
14
 
15
  # === CORE LOGIC ===
16
- def call_kgx3(title, email, pdf_file):
17
- """Send uploaded PDF to the PreprintWatch proxy and show results."""
 
 
18
  if not pdf_file:
19
  return "Please select a PDF file.", ""
20
  pdf_path = pdf_file.name
21
  if not pdf_path.lower().endswith(".pdf"):
22
  return "Only PDF files are supported.", ""
23
 
24
- # Build the Space’s own public 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}"
@@ -46,63 +46,138 @@ def call_kgx3(title, email, pdf_file):
46
  return f"Request error: {e}", file_url
47
 
48
 
49
- # === UI STYLE (modern dark) ===
50
- DARK_CSS = """
51
- * { font-family: 'Inter', 'Roboto', sans-serif !important; }
52
- body, .gradio-container { background-color: #0f1116 !important; color: #e6e6e6 !important; }
53
- label, .label { color: #e6e6e6 !important; font-weight: 500 !important; }
54
- input, textarea, .upload-box, .file-preview {
55
- background: #1b1e25 !important; color: #e6e6e6 !important; border: 1px solid #2c313a !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
 
 
57
  button {
58
- background: #19c37d !important; color: #0f1116 !important; border: none !important;
59
- padding: 10px 18px; font-weight: 600; border-radius: 4px;
 
 
 
 
 
 
 
 
 
60
  }
61
- button:hover { background: #15a86d !important; }
 
62
  pre, code, .cm-editor, .cm-content, .cm-line {
63
- background: #1b1e25 !important; color: #19c37d !important;
64
- border: 1px solid #2c313a !important; border-radius: 4px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  }
66
- .gr-box, .gr-panel { border: 1px solid #2c313a !important; border-radius: 6px; }
67
- footer, .footer, small { color: #6b7078 !important; }
68
  """
69
 
 
 
70
  # === BUILD APP ===
71
  with gr.Blocks(css=DARK_CSS, title="KGX3 Research Analyzer") as demo:
72
  gr.Markdown(
73
  """
74
- #**KGX3 Engine**
75
- Upload a preprint PDF. The app sends it to the KGX3 endpoint serving **PreprintWatch**, which classifies the paper’s paradigm-cycle stage and highlights key findings.
 
76
  """
77
  )
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  with gr.Row():
80
  with gr.Column(scale=1):
81
- title_box = gr.Textbox(
82
- label="Preprint Title",
83
- placeholder="Enter or paste the paper title"
84
- )
85
- email_box = gr.Textbox(
86
- label="Email (optional)",
87
- placeholder="you@example.com"
88
- )
89
- file_box = gr.File(
90
- label="Upload PDF",
91
- file_types=[".pdf"],
92
- type="filepath"
93
- )
94
- run_btn = gr.Button("Run KGX3", variant="primary")
95
- gr.Markdown(
96
- "PDFs are temporarily hosted on this Hugging Face Space "
97
- "and accessible via a direct public link for analysis."
98
- )
99
-
100
  with gr.Column(scale=1):
101
  output_json = gr.Code(label="KGX3 Response", language="json")
102
  output_url = gr.Textbox(label="PDF Link Used", interactive=False)
103
 
104
  run_btn.click(call_kgx3,
105
- inputs=[title_box, email_box, file_box],
106
  outputs=[output_json, output_url])
107
 
108
  gr.Markdown(
@@ -110,4 +185,5 @@ with gr.Blocks(css=DARK_CSS, title="KGX3 Research Analyzer") as demo:
110
  "Thomas Kuhn Foundation © 2025</small>"
111
  )
112
 
 
113
  demo.launch()
 
1
  """
2
+ Shared KGX3 API Endpoint. Includes a user responsibility disclaimer and agreement checkbox.
 
3
  """
4
 
5
  import gradio as gr
6
  import requests, json, pathlib, mimetypes
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
21
  if not pdf_path.lower().endswith(".pdf"):
22
  return "Only PDF files are supported.", ""
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}"
 
46
  return f"Request error: {e}", file_url
47
 
48
 
49
+ # === STYLE (modern dark, clear contrast) ===
50
+ NEON_CSS = """
51
+ /* === GLOBAL === */
52
+ * {
53
+ font-family: 'Courier New', monospace !important;
54
+ color: #00ff99 !important;
55
+ box-sizing: border-box;
56
+ }
57
+ body, .gradio-container {
58
+ background-color: #000 !important;
59
+ color: #00ff99 !important;
60
+ }
61
+
62
+ /* === TEXT ELEMENTS === */
63
+ h1, h2, h3, label, .label {
64
+ color: #00ff99 !important;
65
+ font-weight: 600 !important;
66
+ text-transform: uppercase;
67
+ letter-spacing: 1px;
68
+ border-bottom: 1px solid #00ff99;
69
+ margin-bottom: 6px;
70
+ padding-bottom: 4px;
71
+ }
72
+ p, span, small { color: #00ff99 !important; }
73
+
74
+ /* === INPUTS & TEXTAREAS === */
75
+ input, textarea {
76
+ background: #000 !important;
77
+ border: 1px solid #00ff99 !important;
78
+ color: #00ff99 !important;
79
+ border-radius: 3px;
80
+ padding: 6px 8px !important;
81
+ }
82
+ ::placeholder { color: #00ff99 !important; opacity: 0.6; }
83
+
84
+ /* === PDF UPLOAD BOX === */
85
+ .upload-box, .file-preview, .wrap-inner {
86
+ background: #000 !important;
87
+ border: 2px solid #00ff99 !important;
88
+ border-radius: 6px !important;
89
+ padding: 8px !important;
90
+ height: 48px !important;
91
+ display: flex; align-items: center; justify-content: center;
92
+ }
93
+ .upload-box:hover {
94
+ background: #001a10 !important;
95
  }
96
+
97
+ /* === BUTTONS === */
98
  button {
99
+ background: #000 !important;
100
+ color: #00ff99 !important;
101
+ border: 2px solid #00ff99 !important;
102
+ border-radius: 4px;
103
+ padding: 8px 16px !important;
104
+ font-weight: bold;
105
+ text-transform: uppercase;
106
+ }
107
+ button:hover {
108
+ background: #00ff99 !important;
109
+ color: #000 !important;
110
  }
111
+
112
+ /* === OUTPUT / CODE AREA === */
113
  pre, code, .cm-editor, .cm-content, .cm-line {
114
+ background: #000 !important;
115
+ color: #00ff99 !important;
116
+ border: 1px solid #00ff99 !important;
117
+ border-radius: 4px;
118
+ }
119
+
120
+ /* === PANELS === */
121
+ .gr-box, .gr-panel {
122
+ border: 1px solid #00ff99 !important;
123
+ border-radius: 8px;
124
+ background: #000 !important;
125
+ padding: 12px;
126
+ }
127
+
128
+ /* === SCROLLBARS === */
129
+ ::-webkit-scrollbar { width: 8px; background: #000; }
130
+ ::-webkit-scrollbar-thumb { background: #00ff99; border-radius: 4px; }
131
+
132
+ /* === CHECKBOX === */
133
+ input[type=checkbox] {
134
+ accent-color: #00ff99 !important;
135
+ transform: scale(1.2);
136
  }
 
 
137
  """
138
 
139
+
140
+
141
  # === BUILD APP ===
142
  with gr.Blocks(css=DARK_CSS, title="KGX3 Research Analyzer") as demo:
143
  gr.Markdown(
144
  """
145
+ # 🧠 **KGX3 Research Analyzer**
146
+ Upload a scientific preprint PDF.
147
+ The app sends it to the **PreprintWatch KGX3** API for automated paradigm-cycle analysis.
148
  """
149
  )
150
 
151
+ # --- Disclaimer Section ---
152
+ gr.Markdown(
153
+ """
154
+ ### ⚠️ Disclaimer
155
+ By using this interface, you confirm that:
156
+ - You are solely responsible and accountable for the files you upload.
157
+ - All uploaded files are automatically deleted within **24 hours**.
158
+ - System logs of KGX3 activity are retained securely for **up to 60 days** for service auditing.
159
+ - You must ensure that any material you upload is lawful, non-confidential, and free of third-party rights restrictions.
160
+ """
161
+ )
162
+
163
+ agreement = gr.Checkbox(
164
+ label="I have read and accept full responsibility and accountability for the files I upload.",
165
+ value=False
166
+ )
167
+
168
+ # --- Main input/output layout ---
169
  with gr.Row():
170
  with gr.Column(scale=1):
171
+ title_box = gr.Textbox(label="Preprint Title", placeholder="Enter or paste the paper title")
172
+ email_box = gr.Textbox(label="Email (optional)", placeholder="you@example.com")
173
+ file_box = gr.File(label="Upload PDF", file_types=[".pdf"], type="filepath")
174
+ run_btn = gr.Button("Run KGX3", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  with gr.Column(scale=1):
176
  output_json = gr.Code(label="KGX3 Response", language="json")
177
  output_url = gr.Textbox(label="PDF Link Used", interactive=False)
178
 
179
  run_btn.click(call_kgx3,
180
+ inputs=[title_box, email_box, file_box, agreement],
181
  outputs=[output_json, output_url])
182
 
183
  gr.Markdown(
 
185
  "Thomas Kuhn Foundation © 2025</small>"
186
  )
187
 
188
+
189
  demo.launch()