Spaces:
Running
on
Zero
Running
on
Zero
Model works with updated server_name and ssr_mode false, and added client x-ip-token to fix zeroGPU timeout but now am at back of GPU queue
Browse files
app.py
CHANGED
@@ -49,6 +49,8 @@ References
|
|
49 |
"""
|
50 |
|
51 |
import spaces
|
|
|
|
|
52 |
import subprocess
|
53 |
import sys
|
54 |
import json
|
@@ -138,8 +140,7 @@ from quantum_utils import run_vqe_simulation
|
|
138 |
from visualization import plot_convergence, create_molecule_viewer, format_molecule_params
|
139 |
from gradio_molgallery3d import MolGallery3D
|
140 |
|
141 |
-
|
142 |
-
client = Client("your-space", headers={"X-IP-Token": request.headers['x-ip-token']})
|
143 |
|
144 |
# Add immediate logging
|
145 |
print("Imported all modules successfully", file=sys.stderr, flush=True)
|
@@ -204,6 +205,18 @@ def update_simulation(molecule_choice: str, scale_factor: float) -> tuple:
|
|
204 |
def create_interface():
|
205 |
"""Create the Gradio interface for the VQE demo."""
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
# Load available molecules
|
208 |
molecules = load_molecules()
|
209 |
if not molecules:
|
@@ -233,6 +246,8 @@ def create_interface():
|
|
233 |
*Inspired by the [NVIDIA CUDA-Q VQE Example](https://nvidia.github.io/cuda-quantum/latest/applications/python/vqe_advanced.html)*
|
234 |
""")
|
235 |
|
|
|
|
|
236 |
state = gr.State({}) # Store current molecule data
|
237 |
|
238 |
# Top section: 3 columns
|
@@ -499,11 +514,19 @@ def create_interface():
|
|
499 |
inputs=[molecule_choice, scale_factor],
|
500 |
outputs=[simulation_results, convergence_plot]
|
501 |
)
|
502 |
-
|
|
|
|
|
|
|
503 |
return demo
|
504 |
|
505 |
if __name__ == "__main__":
|
506 |
print("Starting VQE Demo Application")
|
507 |
demo = create_interface()
|
508 |
-
print("
|
509 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
49 |
"""
|
50 |
|
51 |
import spaces
|
52 |
+
from gradio_client import Client
|
53 |
+
from gradio.routes import Request as gr_Request
|
54 |
import subprocess
|
55 |
import sys
|
56 |
import json
|
|
|
140 |
from visualization import plot_convergence, create_molecule_viewer, format_molecule_params
|
141 |
from gradio_molgallery3d import MolGallery3D
|
142 |
|
143 |
+
#Todo later add this working client stuff to fix timeouts client = Client("your-space", headers={"X-IP-Token": request.headers['x-ip-token']})
|
|
|
144 |
|
145 |
# Add immediate logging
|
146 |
print("Imported all modules successfully", file=sys.stderr, flush=True)
|
|
|
205 |
def create_interface():
|
206 |
"""Create the Gradio interface for the VQE demo."""
|
207 |
|
208 |
+
def set_client_for_session(request: gr.Request):
|
209 |
+
"""Initialize client with user's IP token to handle rate limiting."""
|
210 |
+
# from https://www.gradio.app/docs/python-client/using-zero-gpu-spaces
|
211 |
+
try:
|
212 |
+
x_ip_token = request.headers['x-ip-token'] #
|
213 |
+
return Client("A19grey/Cuda-Quantum-Molecular-Playground", headers={"x-ip-token": x_ip_token})
|
214 |
+
except Exception as e:
|
215 |
+
logger.error(f"Error setting client: {e}")
|
216 |
+
return None
|
217 |
+
|
218 |
+
|
219 |
+
|
220 |
# Load available molecules
|
221 |
molecules = load_molecules()
|
222 |
if not molecules:
|
|
|
246 |
*Inspired by the [NVIDIA CUDA-Q VQE Example](https://nvidia.github.io/cuda-quantum/latest/applications/python/vqe_advanced.html)*
|
247 |
""")
|
248 |
|
249 |
+
client = gr.State() # added this to fix timeouts - https://www.gradio.app/docs/python-client/using-zero-gpu-spaces
|
250 |
+
|
251 |
state = gr.State({}) # Store current molecule data
|
252 |
|
253 |
# Top section: 3 columns
|
|
|
514 |
inputs=[molecule_choice, scale_factor],
|
515 |
outputs=[simulation_results, convergence_plot]
|
516 |
)
|
517 |
+
|
518 |
+
# Add load event to set client
|
519 |
+
demo.load(set_client_for_session, None, client)
|
520 |
+
|
521 |
return demo
|
522 |
|
523 |
if __name__ == "__main__":
|
524 |
print("Starting VQE Demo Application")
|
525 |
demo = create_interface()
|
526 |
+
print("Launching demo with custom headers support")
|
527 |
+
demo.launch(
|
528 |
+
server_name="0.0.0.0",
|
529 |
+
server_port=7860,
|
530 |
+
ssr_mode=False,
|
531 |
+
show_api=True # Enable API endpoints
|
532 |
+
)
|