tdoehmen commited on
Commit
f9d0ccd
1 Parent(s): 4a950e5

just use openrouter

Browse files
Files changed (2) hide show
  1. app.py +15 -35
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,39 +1,23 @@
1
  import gradio as gr
2
  import subprocess
3
- 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
- cd duckdb-nsql/ &&
26
- CUDA_VISIBLE_DEVICES=0 HF_TOKEN={os.environ['HF_TOKEN']} 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.PIPE)
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 \
@@ -42,12 +26,13 @@ def run_evaluation(model_name):
42
  eval/data/tables.json \
43
  --output-dir output/ \
44
  --stop-tokens ';' \
 
45
  --overwrite-manifest \
46
- --manifest-client huggingface \
47
- --manifest-connection http://localhost:5000 \
48
  --prompt-format duckdbinstgraniteshort
49
  """
50
- inference_result = subprocess.run(inference_cmd, shell=True, check=True, capture_output=True, text=True)
51
  results.append("Inference completed.")
52
 
53
  # Extract JSON file path from inference output
@@ -74,25 +59,20 @@ 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)}")
81
  results.append(f"Command output: {e.output}")
82
  except Exception as e:
83
  results.append(f"An unexpected error occurred: {str(e)}")
84
- finally:
85
- # Terminate the background manifest server
86
- if manifest_process:
87
- manifest_process.terminate()
88
- results.append("Terminated manifest server.")
89
 
90
  return "\n\n".join(results)
91
 
92
  with gr.Blocks() as demo:
93
- gr.Markdown("# DuckDB SQL Evaluation App")
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
 
 
1
  import gradio as gr
2
  import subprocess
 
 
3
  import os
4
  import re
5
+ from datetime import datetime
6
 
 
 
 
 
7
  def run_evaluation(model_name):
 
 
8
  results = []
9
 
10
+ # Use the secret OpenRouter API key from the Hugging Face space
11
+ if "OPENROUTER_API_KEY" not in os.environ:
12
+ return "Error: OPENROUTER_API_KEY not found in environment variables."
13
 
 
14
  try:
15
+ # Set up environment
16
+ env = os.environ.copy()
17
+ env["OPENROUTER_API_KEY"] = os.environ["OPENROUTER_API_KEY"]
 
 
 
 
 
 
 
 
 
18
 
19
  # Run inference
20
+ current_date = datetime.now().strftime("%Y%m%d")
21
  inference_cmd = f"""
22
  cd duckdb-nsql/ &&
23
  python eval/predict.py \
 
26
  eval/data/tables.json \
27
  --output-dir output/ \
28
  --stop-tokens ';' \
29
+ --max-tokens 30000 \
30
  --overwrite-manifest \
31
+ --manifest-client openrouter \
32
+ --manifest-engine {model_name} \
33
  --prompt-format duckdbinstgraniteshort
34
  """
35
+ inference_result = subprocess.run(inference_cmd, shell=True, check=True, capture_output=True, text=True, env=env)
36
  results.append("Inference completed.")
37
 
38
  # Extract JSON file path from inference output
 
59
  if metrics:
60
  results.append(f"Evaluation completed:\n{metrics}")
61
  else:
62
+ results.append("Evaluation completed, but couldn't get metrics.")
63
 
64
  except subprocess.CalledProcessError as e:
65
  results.append(f"Error occurred: {str(e)}")
66
  results.append(f"Command output: {e.output}")
67
  except Exception as e:
68
  results.append(f"An unexpected error occurred: {str(e)}")
 
 
 
 
 
69
 
70
  return "\n\n".join(results)
71
 
72
  with gr.Blocks() as demo:
73
+ gr.Markdown("# DuckDB SQL Evaluation App (OpenRouter)")
74
 
75
+ model_name = gr.Textbox(label="Model Name (e.g., qwen/qwen-2.5-72b-instruct)")
76
  start_btn = gr.Button("Start Evaluation")
77
  output = gr.Textbox(label="Output", lines=20)
78
 
requirements.txt CHANGED
@@ -22,7 +22,8 @@ ninja==1.11.1.1
22
  langchain
23
  pydantic
24
  packaging
25
- manifest-ml @ git+https://github.com/tdoehmen/manifest@till/added_openrouter
 
26
  flask
27
  diffusers
28
  deepspeed
 
22
  langchain
23
  pydantic
24
  packaging
25
+ -e duckdb-nsql/manifest
26
+ # manifest-ml @ git+https://github.com/tdoehmen/manifest@till/added_openrouter
27
  flask
28
  diffusers
29
  deepspeed