Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import llm_blender
|
| 3 |
+
|
| 4 |
+
# Load the model and explicitly force it to use the CPU
|
| 5 |
+
blender = llm_blender.Blender()
|
| 6 |
+
blender.loadranker("llm-blender/PairRM", device="cpu")
|
| 7 |
+
|
| 8 |
+
def score_pair(prompt, cand_a, cand_b):
|
| 9 |
+
inputs = [prompt]
|
| 10 |
+
candidates_A = [cand_a]
|
| 11 |
+
candidates_B = [cand_b]
|
| 12 |
+
|
| 13 |
+
# Compare returns a list of booleans (True if A is better)
|
| 14 |
+
comparison_results = blender.compare(inputs, candidates_A, candidates_B)
|
| 15 |
+
|
| 16 |
+
return "A" if comparison_results[0] else "B"
|
| 17 |
+
|
| 18 |
+
# Create the API endpoint
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=score_pair,
|
| 21 |
+
inputs=["text", "text", "text"],
|
| 22 |
+
outputs="text"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
iface.launch()
|