bergr7f commited on
Commit
06826f1
1 Parent(s): 9447ed2

download model and load inside evalaute

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -4,15 +4,19 @@ import pandas as pd
4
  from typing import List, Dict
5
  from flow_judge import Hf, FlowJudge, EvalInput
6
  from flow_judge.metrics import CustomMetric, RubricItem
 
 
7
 
 
8
 
9
- @spaces.GPU
10
- def load_model():
11
  try:
12
- model = Hf(flash_attn=False)
13
- return model
14
- except Exception as e:
15
- raise RuntimeError(f"Failed to initialize Hf Model: {e}")
 
 
16
 
17
  EXAMPLES = [
18
  {
@@ -40,7 +44,13 @@ def populate_fields(example_index: int):
40
  )
41
 
42
  @spaces.GPU
43
- def evaluate(model, task_inputs: pd.DataFrame, task_output: pd.DataFrame, evaluation_criteria: str, rubric: pd.DataFrame) -> tuple:
 
 
 
 
 
 
44
  # Convert inputs to the expected format
45
  eval_input = EvalInput(
46
  inputs=[{row['Name']: row['Value']} for _, row in task_inputs.iterrows()],
@@ -100,7 +110,7 @@ def reset_evaluation_criteria():
100
  )
101
 
102
  with gr.Blocks() as demo:
103
- model = load_model()
104
  with gr.Row():
105
  example_buttons = [gr.Button(f"{example['emoji']} Example {i+1}") for i, example in enumerate(EXAMPLES)]
106
 
@@ -184,7 +194,7 @@ with gr.Blocks() as demo:
184
 
185
  evaluate_btn.click(
186
  evaluate,
187
- inputs=[model,task_inputs, task_output, evaluation_criteria, rubric],
188
  outputs=[feedback, score]
189
  )
190
 
 
4
  from typing import List, Dict
5
  from flow_judge import Hf, FlowJudge, EvalInput
6
  from flow_judge.metrics import CustomMetric, RubricItem
7
+ from huggingface_hub import snapshot_download
8
+ from flow_judge.models.huggingface import Hf
9
 
10
+ MODEL_NAME = "flowaicom/Flow-Judge-v0.1"
11
 
12
+ def download_model():
 
13
  try:
14
+ print(f"Downloading model {MODEL_NAME}...")
15
+ snapshot_download(repo_id=MODEL_NAME)
16
+ print(f"Model {MODEL_NAME} downloaded to default Hugging Face cache")
17
+ return True
18
+ except Exception as e:
19
+ raise RuntimeError(f"Failed to download model {MODEL_NAME}: {e}")
20
 
21
  EXAMPLES = [
22
  {
 
44
  )
45
 
46
  @spaces.GPU
47
+ def evaluate(task_inputs: pd.DataFrame, task_output: pd.DataFrame, evaluation_criteria: str, rubric: pd.DataFrame) -> tuple:
48
+ # Load the model
49
+ try:
50
+ model = Hf(flash_attn=False)
51
+ except Exception as e:
52
+ raise RuntimeError(f"Failed to initialize Hf Model: {e}")
53
+
54
  # Convert inputs to the expected format
55
  eval_input = EvalInput(
56
  inputs=[{row['Name']: row['Value']} for _, row in task_inputs.iterrows()],
 
110
  )
111
 
112
  with gr.Blocks() as demo:
113
+ model_downloaded = download_model()
114
  with gr.Row():
115
  example_buttons = [gr.Button(f"{example['emoji']} Example {i+1}") for i, example in enumerate(EXAMPLES)]
116
 
 
194
 
195
  evaluate_btn.click(
196
  evaluate,
197
+ inputs=[task_inputs, task_output, evaluation_criteria, rubric],
198
  outputs=[feedback, score]
199
  )
200