Spaces:
Sleeping
Sleeping
Kolumbus Lindh
commited on
Commit
·
8f23865
1
Parent(s):
66cb564
updates
Browse files
app.py
CHANGED
@@ -2,36 +2,27 @@ import gradio as gr
|
|
2 |
from llama_cpp import Llama
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
|
5 |
-
#
|
6 |
-
def
|
7 |
-
|
8 |
-
model_file = "unsloth.F16.gguf"
|
9 |
local_path = hf_hub_download(repo_id=repo_id, filename=model_file)
|
10 |
-
print(f"
|
11 |
return Llama(model_path=local_path, n_ctx=2048, n_threads=8)
|
12 |
|
13 |
-
lora_model = load_lora_model()
|
14 |
-
print("LoRA model loaded successfully!")
|
15 |
-
|
16 |
-
# Function to load a user-specified model
|
17 |
-
def load_user_model(model_path):
|
18 |
-
print(f"Loading user model from: {model_path}")
|
19 |
-
return Llama(model_path=model_path, n_ctx=2048, n_threads=8)
|
20 |
-
|
21 |
# Generate a response using the specified model and prompt
|
22 |
def generate_response(model, prompt):
|
23 |
response = model(prompt, max_tokens=256, temperature=0.7)
|
24 |
return response["choices"][0]["text"]
|
25 |
|
26 |
-
# Evaluate responses generated by two models using the LoRA model
|
27 |
-
def evaluate_responses(prompt,
|
28 |
# Load user-specified models
|
29 |
-
|
30 |
-
|
31 |
|
32 |
# Generate responses
|
33 |
-
response_a = generate_response(
|
34 |
-
response_b = generate_response(
|
35 |
|
36 |
print(f"Response A: {response_a}")
|
37 |
print(f"Response B: {response_b}")
|
@@ -55,13 +46,31 @@ Please evaluate the responses based on the criteria above. Rate each response on
|
|
55 |
)
|
56 |
return evaluation_response["choices"][0]["text"]
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Gradio interface
|
59 |
with gr.Blocks(title="LLM as a Judge") as demo:
|
60 |
gr.Markdown("## LLM as a Judge 🧐")
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
prompt_input = gr.Textbox(label="Enter Prompt", placeholder="Enter the prompt here...", lines=3)
|
66 |
criteria_dropdown = gr.Dropdown(
|
67 |
label="Select Evaluation Criteria",
|
@@ -69,7 +78,11 @@ with gr.Blocks(title="LLM as a Judge") as demo:
|
|
69 |
value="Clarity",
|
70 |
type="value"
|
71 |
)
|
|
|
|
|
72 |
evaluate_button = gr.Button("Evaluate Models")
|
|
|
|
|
73 |
evaluation_output = gr.Textbox(
|
74 |
label="Evaluation Results",
|
75 |
placeholder="The evaluation results will appear here...",
|
@@ -80,10 +93,10 @@ with gr.Blocks(title="LLM as a Judge") as demo:
|
|
80 |
# Link the evaluation function to the button
|
81 |
evaluate_button.click(
|
82 |
fn=evaluate_responses,
|
83 |
-
inputs=[prompt_input, model_a_input, model_b_input, criteria_dropdown],
|
84 |
outputs=[evaluation_output]
|
85 |
)
|
86 |
|
87 |
# Launch the Gradio app
|
88 |
if __name__ == "__main__":
|
89 |
-
demo.launch()
|
|
|
2 |
from llama_cpp import Llama
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
|
5 |
+
# Function to load a user-specified model from Hugging Face
|
6 |
+
def load_user_model(repo_id, model_file):
|
7 |
+
print(f"Downloading model {model_file} from repository {repo_id}...")
|
|
|
8 |
local_path = hf_hub_download(repo_id=repo_id, filename=model_file)
|
9 |
+
print(f"Model downloaded to: {local_path}")
|
10 |
return Llama(model_path=local_path, n_ctx=2048, n_threads=8)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Generate a response using the specified model and prompt
|
13 |
def generate_response(model, prompt):
|
14 |
response = model(prompt, max_tokens=256, temperature=0.7)
|
15 |
return response["choices"][0]["text"]
|
16 |
|
17 |
+
# Evaluate responses generated by two models using the LoRA evaluation model
|
18 |
+
def evaluate_responses(prompt, repo_a, model_a, repo_b, model_b, evaluation_criteria):
|
19 |
# Load user-specified models
|
20 |
+
model_a_instance = load_user_model(repo_a, model_a)
|
21 |
+
model_b_instance = load_user_model(repo_b, model_b)
|
22 |
|
23 |
# Generate responses
|
24 |
+
response_a = generate_response(model_a_instance, prompt)
|
25 |
+
response_b = generate_response(model_b_instance, prompt)
|
26 |
|
27 |
print(f"Response A: {response_a}")
|
28 |
print(f"Response B: {response_b}")
|
|
|
46 |
)
|
47 |
return evaluation_response["choices"][0]["text"]
|
48 |
|
49 |
+
# Load the base LoRA evaluation model
|
50 |
+
def load_lora_model():
|
51 |
+
repo_id = "KolumbusLindh/LoRA-4100"
|
52 |
+
model_file = "unsloth.F16.gguf"
|
53 |
+
print(f"Downloading LoRA evaluation model from repository {repo_id}...")
|
54 |
+
local_path = hf_hub_download(repo_id=repo_id, filename=model_file)
|
55 |
+
print(f"LoRA evaluation model downloaded to: {local_path}")
|
56 |
+
return Llama(model_path=local_path, n_ctx=2048, n_threads=8)
|
57 |
+
|
58 |
+
lora_model = load_lora_model()
|
59 |
+
print("LoRA evaluation model loaded successfully!")
|
60 |
+
|
61 |
# Gradio interface
|
62 |
with gr.Blocks(title="LLM as a Judge") as demo:
|
63 |
gr.Markdown("## LLM as a Judge 🧐")
|
64 |
|
65 |
+
# Inputs for Model A repository and file
|
66 |
+
repo_a_input = gr.Textbox(label="Model A Repository (e.g., KolumbusLindh/LoRA-4100)", placeholder="Enter the Hugging Face repo name for Model A...")
|
67 |
+
model_a_input = gr.Textbox(label="Model A File Name (e.g., unsloth.F16.gguf)", placeholder="Enter the model filename for Model A...")
|
68 |
+
|
69 |
+
# Inputs for Model B repository and file
|
70 |
+
repo_b_input = gr.Textbox(label="Model B Repository (e.g., KolumbusLindh/LoRA-4100)", placeholder="Enter the Hugging Face repo name for Model B...")
|
71 |
+
model_b_input = gr.Textbox(label="Model B File Name (e.g., unsloth.F16.gguf)", placeholder="Enter the model filename for Model B...")
|
72 |
+
|
73 |
+
# Input for prompt and evaluation criteria
|
74 |
prompt_input = gr.Textbox(label="Enter Prompt", placeholder="Enter the prompt here...", lines=3)
|
75 |
criteria_dropdown = gr.Dropdown(
|
76 |
label="Select Evaluation Criteria",
|
|
|
78 |
value="Clarity",
|
79 |
type="value"
|
80 |
)
|
81 |
+
|
82 |
+
# Button to evaluate responses
|
83 |
evaluate_button = gr.Button("Evaluate Models")
|
84 |
+
|
85 |
+
# Output for evaluation results
|
86 |
evaluation_output = gr.Textbox(
|
87 |
label="Evaluation Results",
|
88 |
placeholder="The evaluation results will appear here...",
|
|
|
93 |
# Link the evaluation function to the button
|
94 |
evaluate_button.click(
|
95 |
fn=evaluate_responses,
|
96 |
+
inputs=[prompt_input, repo_a_input, model_a_input, repo_b_input, model_b_input, criteria_dropdown],
|
97 |
outputs=[evaluation_output]
|
98 |
)
|
99 |
|
100 |
# Launch the Gradio app
|
101 |
if __name__ == "__main__":
|
102 |
+
demo.launch() # Add share=True to create a public link
|