Spaces:
Runtime error
Runtime error
download model and load inside evalaute
Browse files
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 |
-
|
| 10 |
-
def load_model():
|
| 11 |
try:
|
| 12 |
-
model
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
EXAMPLES = [
|
| 18 |
{
|
|
@@ -40,7 +44,13 @@ def populate_fields(example_index: int):
|
|
| 40 |
)
|
| 41 |
|
| 42 |
@spaces.GPU
|
| 43 |
-
def evaluate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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=[
|
| 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 |
|