Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
cf3d2b0
1
Parent(s):
1e70cce
update
Browse files
app.py
CHANGED
@@ -29,7 +29,6 @@ def verify_answer(question, ground_truth, model_answer, temperature, top_p, max_
|
|
29 |
|
30 |
# Prepare the message format required by the API
|
31 |
messages = [
|
32 |
-
{"role": "system", "content": "You are a helpful AI assistant that verifies answers."},
|
33 |
{"role": "user", "content": prompt}
|
34 |
]
|
35 |
|
@@ -53,12 +52,10 @@ def verify_answer(question, ground_truth, model_answer, temperature, top_p, max_
|
|
53 |
yield f"Error: {str(e)}"
|
54 |
|
55 |
# Create the Gradio interface
|
56 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Answer Verification Tool") as demo:
|
57 |
# Header with title and description
|
58 |
with gr.Row():
|
59 |
-
with gr.Column(
|
60 |
-
gr.Image("https://huggingface.co/front/assets/huggingface_logo.svg", scale=1, show_label=False, height=64)
|
61 |
-
with gr.Column(scale=5):
|
62 |
gr.Markdown(
|
63 |
"""
|
64 |
# Answer Verification Tool
|
@@ -99,8 +96,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Answer Verificat
|
|
99 |
model_answer="Paris is the capital of France.",
|
100 |
temperature=0.3,
|
101 |
top_p=0.95,
|
102 |
-
max_tokens=
|
103 |
-
api_name="/
|
104 |
)
|
105 |
print(result)
|
106 |
```
|
@@ -111,7 +108,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Answer Verificat
|
|
111 |
with gr.Accordion("Advanced Settings", open=False):
|
112 |
temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.3, step=0.1, label="Temperature")
|
113 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
114 |
-
max_tokens = gr.Slider(minimum=32, maximum=512, value=
|
115 |
|
116 |
with gr.Column(scale=1):
|
117 |
gr.Markdown("## Input")
|
@@ -131,56 +128,67 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Answer Verificat
|
|
131 |
outputs=result
|
132 |
)
|
133 |
|
134 |
-
# Examples
|
135 |
with gr.Accordion("Examples", open=True):
|
136 |
-
gr.
|
137 |
-
|
138 |
-
[
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
153 |
],
|
154 |
-
[
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
[
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
],
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
174 |
|
175 |
# Add footer with extra information
|
176 |
-
with gr.Row():
|
177 |
gr.Markdown(
|
178 |
"""
|
179 |
### About
|
180 |
-
This tool uses the zhangchenxu/TinyV-1.5B model to verify answers
|
181 |
-
|
182 |
-
The verification is based on semantic similarity rather than exact matching,
|
183 |
-
allowing for different phrasings and formats of the same correct answer.
|
184 |
"""
|
185 |
)
|
186 |
|
|
|
29 |
|
30 |
# Prepare the message format required by the API
|
31 |
messages = [
|
|
|
32 |
{"role": "user", "content": prompt}
|
33 |
]
|
34 |
|
|
|
52 |
yield f"Error: {str(e)}"
|
53 |
|
54 |
# Create the Gradio interface
|
55 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]), title="Answer Verification Tool") as demo:
|
56 |
# Header with title and description
|
57 |
with gr.Row():
|
58 |
+
with gr.Column():
|
|
|
|
|
59 |
gr.Markdown(
|
60 |
"""
|
61 |
# Answer Verification Tool
|
|
|
96 |
model_answer="Paris is the capital of France.",
|
97 |
temperature=0.3,
|
98 |
top_p=0.95,
|
99 |
+
max_tokens=1,
|
100 |
+
api_name="/verify_answer"
|
101 |
)
|
102 |
print(result)
|
103 |
```
|
|
|
108 |
with gr.Accordion("Advanced Settings", open=False):
|
109 |
temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.3, step=0.1, label="Temperature")
|
110 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
111 |
+
max_tokens = gr.Slider(minimum=32, maximum=512, value=1, step=32, label="Max Tokens")
|
112 |
|
113 |
with gr.Column(scale=1):
|
114 |
gr.Markdown("## Input")
|
|
|
128 |
outputs=result
|
129 |
)
|
130 |
|
131 |
+
# Examples section - improved styling
|
132 |
with gr.Accordion("Examples", open=True):
|
133 |
+
with gr.Row():
|
134 |
+
gr.Examples(
|
135 |
+
examples=[
|
136 |
+
[
|
137 |
+
"What is the capital of France?",
|
138 |
+
"The capital of France is Paris.",
|
139 |
+
"Paris is the capital of France.",
|
140 |
+
0.3,
|
141 |
+
0.95,
|
142 |
+
2,
|
143 |
+
],
|
144 |
+
[
|
145 |
+
"What is 2+2?",
|
146 |
+
"4",
|
147 |
+
"Four.",
|
148 |
+
0.3,
|
149 |
+
0.95,
|
150 |
+
2,
|
151 |
+
],
|
152 |
],
|
153 |
+
inputs=[question, ground_truth, model_answer, temperature, top_p, max_tokens],
|
154 |
+
outputs=result,
|
155 |
+
fn=verify_answer,
|
156 |
+
cache_examples=True,
|
157 |
+
)
|
158 |
+
|
159 |
+
with gr.Row():
|
160 |
+
gr.Examples(
|
161 |
+
examples=[
|
162 |
+
[
|
163 |
+
"When was the Declaration of Independence signed?",
|
164 |
+
"July 4, 1776",
|
165 |
+
"The Declaration of Independence was signed on July 4th, 1776.",
|
166 |
+
0.3,
|
167 |
+
0.95,
|
168 |
+
2,
|
169 |
+
],
|
170 |
+
[
|
171 |
+
"List the first three planets from the sun.",
|
172 |
+
"Mercury, Venus, Earth",
|
173 |
+
"The first three planets from the sun are Mercury, Venus, and Earth.",
|
174 |
+
0.3,
|
175 |
+
0.95,
|
176 |
+
2,
|
177 |
+
],
|
178 |
],
|
179 |
+
inputs=[question, ground_truth, model_answer, temperature, top_p, max_tokens],
|
180 |
+
outputs=result,
|
181 |
+
fn=verify_answer,
|
182 |
+
cache_examples=True,
|
183 |
+
)
|
184 |
|
185 |
# Add footer with extra information
|
186 |
+
with gr.Row(equal_height=True):
|
187 |
gr.Markdown(
|
188 |
"""
|
189 |
### About
|
190 |
+
This tool uses the zhangchenxu/TinyV-1.5B model to verify the correctness of the answers,
|
191 |
+
allowing for different phrasings of correct answers.
|
|
|
|
|
192 |
"""
|
193 |
)
|
194 |
|