Spaces:
Running
Running
show manifest output
Browse files
app.py
CHANGED
@@ -4,38 +4,60 @@ import spaces
|
|
4 |
import torch
|
5 |
import os
|
6 |
import re
|
|
|
|
|
7 |
|
8 |
zero = torch.Tensor([0]).cuda()
|
9 |
print(zero.device) # <-- 'cpu' π€
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
@spaces.GPU
|
12 |
def run_evaluation(model_name):
|
13 |
print(zero.device) # <-- 'cuda:0' π€
|
14 |
|
15 |
results = []
|
|
|
16 |
|
17 |
# Use the secret HF token from the Hugging Face space
|
18 |
if "HF_TOKEN" not in os.environ:
|
19 |
-
return "Error: HF_TOKEN not found in environment variables."
|
20 |
|
21 |
manifest_process = None
|
|
|
22 |
try:
|
23 |
# Start manifest server in background with explicit CUDA_VISIBLE_DEVICES
|
24 |
manifest_cmd = f"""
|
25 |
-
|
26 |
-
python -m manifest.api.app \
|
27 |
--model_type huggingface \
|
28 |
--model_generation_type text-generation \
|
29 |
--model_name_or_path {model_name} \
|
30 |
--fp16 \
|
31 |
--device 0
|
32 |
"""
|
33 |
-
manifest_process = subprocess.Popen(manifest_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.
|
|
|
|
|
|
|
34 |
results.append("Started manifest server in background.")
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# Run inference
|
37 |
inference_cmd = f"""
|
38 |
-
cd duckdb-nsql/ &&
|
39 |
python eval/predict.py \
|
40 |
predict \
|
41 |
eval/data/dev.json \
|
@@ -59,7 +81,7 @@ def run_evaluation(model_name):
|
|
59 |
|
60 |
# Run evaluation
|
61 |
eval_cmd = f"""
|
62 |
-
cd duckdb-nsql/ &&
|
63 |
python eval/evaluate.py evaluate \
|
64 |
--gold eval/data/dev.json \
|
65 |
--db eval/data/databases/ \
|
@@ -74,7 +96,7 @@ def run_evaluation(model_name):
|
|
74 |
if metrics:
|
75 |
results.append(f"Evaluation completed:\n{metrics}")
|
76 |
else:
|
77 |
-
results.append("Evaluation completed, but get metrics.")
|
78 |
|
79 |
except subprocess.CalledProcessError as e:
|
80 |
results.append(f"Error occurred: {str(e)}")
|
@@ -87,15 +109,24 @@ def run_evaluation(model_name):
|
|
87 |
manifest_process.terminate()
|
88 |
results.append("Terminated manifest server.")
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
with gr.Blocks() as demo:
|
93 |
-
gr.Markdown("# DuckDB
|
94 |
|
95 |
model_name = gr.Textbox(label="Model Name (e.g., Qwen/Qwen2.5-7B-Instruct)")
|
96 |
start_btn = gr.Button("Start Evaluation")
|
97 |
-
output = gr.Textbox(label="Output", lines=20)
|
|
|
98 |
|
99 |
-
start_btn.click(fn=run_evaluation, inputs=[model_name], outputs=output)
|
100 |
|
101 |
demo.launch()
|
|
|
4 |
import torch
|
5 |
import os
|
6 |
import re
|
7 |
+
import threading
|
8 |
+
import queue
|
9 |
|
10 |
zero = torch.Tensor([0]).cuda()
|
11 |
print(zero.device) # <-- 'cpu' π€
|
12 |
|
13 |
+
def stream_output(process, q):
|
14 |
+
for line in iter(process.stdout.readline, b''):
|
15 |
+
q.put(line.decode('utf-8').strip())
|
16 |
+
process.stdout.close()
|
17 |
+
|
18 |
@spaces.GPU
|
19 |
def run_evaluation(model_name):
|
20 |
print(zero.device) # <-- 'cuda:0' π€
|
21 |
|
22 |
results = []
|
23 |
+
manifest_logs = []
|
24 |
|
25 |
# Use the secret HF token from the Hugging Face space
|
26 |
if "HF_TOKEN" not in os.environ:
|
27 |
+
return "Error: HF_TOKEN not found in environment variables.", "Error: Cannot start manifest server without HF_TOKEN."
|
28 |
|
29 |
manifest_process = None
|
30 |
+
log_queue = queue.Queue()
|
31 |
try:
|
32 |
# Start manifest server in background with explicit CUDA_VISIBLE_DEVICES
|
33 |
manifest_cmd = f"""
|
34 |
+
cd duckdb-nsql/ &&
|
35 |
+
CUDA_VISIBLE_DEVICES=0 HF_TOKEN={os.environ['HF_TOKEN']} python -m manifest.api.app \
|
36 |
--model_type huggingface \
|
37 |
--model_generation_type text-generation \
|
38 |
--model_name_or_path {model_name} \
|
39 |
--fp16 \
|
40 |
--device 0
|
41 |
"""
|
42 |
+
manifest_process = subprocess.Popen(manifest_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True)
|
43 |
+
|
44 |
+
threading.Thread(target=stream_output, args=(manifest_process, log_queue), daemon=True).start()
|
45 |
+
|
46 |
results.append("Started manifest server in background.")
|
47 |
|
48 |
+
# Wait for the server to initialize (adjust time as needed)
|
49 |
+
for _ in range(30):
|
50 |
+
try:
|
51 |
+
line = log_queue.get(timeout=1)
|
52 |
+
manifest_logs.append(line)
|
53 |
+
if "Running on" in line: # Server is ready
|
54 |
+
break
|
55 |
+
except queue.Empty:
|
56 |
+
pass
|
57 |
+
|
58 |
# Run inference
|
59 |
inference_cmd = f"""
|
60 |
+
cd duckdb-nsql/ &&
|
61 |
python eval/predict.py \
|
62 |
predict \
|
63 |
eval/data/dev.json \
|
|
|
81 |
|
82 |
# Run evaluation
|
83 |
eval_cmd = f"""
|
84 |
+
cd duckdb-nsql/ &&
|
85 |
python eval/evaluate.py evaluate \
|
86 |
--gold eval/data/dev.json \
|
87 |
--db eval/data/databases/ \
|
|
|
96 |
if metrics:
|
97 |
results.append(f"Evaluation completed:\n{metrics}")
|
98 |
else:
|
99 |
+
results.append("Evaluation completed, but couldn't get metrics.")
|
100 |
|
101 |
except subprocess.CalledProcessError as e:
|
102 |
results.append(f"Error occurred: {str(e)}")
|
|
|
109 |
manifest_process.terminate()
|
110 |
results.append("Terminated manifest server.")
|
111 |
|
112 |
+
# Collect any remaining logs
|
113 |
+
while True:
|
114 |
+
try:
|
115 |
+
line = log_queue.get_nowait()
|
116 |
+
manifest_logs.append(line)
|
117 |
+
except queue.Empty:
|
118 |
+
break
|
119 |
+
|
120 |
+
return "\n\n".join(results), "\n".join(manifest_logs)
|
121 |
|
122 |
with gr.Blocks() as demo:
|
123 |
+
gr.Markdown("# DuckDB SQL Evaluation App")
|
124 |
|
125 |
model_name = gr.Textbox(label="Model Name (e.g., Qwen/Qwen2.5-7B-Instruct)")
|
126 |
start_btn = gr.Button("Start Evaluation")
|
127 |
+
output = gr.Textbox(label="Evaluation Output", lines=20)
|
128 |
+
manifest_output = gr.Textbox(label="Manifest Server Logs", lines=20)
|
129 |
|
130 |
+
start_btn.click(fn=run_evaluation, inputs=[model_name], outputs=[output, manifest_output])
|
131 |
|
132 |
demo.launch()
|