Spaces:
Running
Running
acumplid
commited on
Commit
•
3b1628f
1
Parent(s):
1983ef1
Added sources and modified layout
Browse files
app.py
CHANGED
@@ -24,8 +24,8 @@ rag = RAG(
|
|
24 |
|
25 |
def generate(prompt, model_parameters):
|
26 |
try:
|
27 |
-
output, context = rag.get_response(prompt, model_parameters)
|
28 |
-
return output, context
|
29 |
except HTTPError as err:
|
30 |
if err.code == 400:
|
31 |
gr.Warning(
|
@@ -54,8 +54,13 @@ def submit_input(input_, num_chunks, max_new_tokens, repetition_penalty, top_k,
|
|
54 |
"TEMPERATURE": temperature
|
55 |
}
|
56 |
|
57 |
-
output, context = generate(input_, model_parameters)
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
def change_interactive(text):
|
@@ -70,6 +75,7 @@ def clear():
|
|
70 |
None,
|
71 |
None,
|
72 |
None,
|
|
|
73 |
gr.Slider(value=100),
|
74 |
gr.Slider(value=1.2),
|
75 |
gr.Slider(value=50),
|
@@ -172,18 +178,21 @@ def gradio_app():
|
|
172 |
|
173 |
with gr.Column(variant="panel"):
|
174 |
output = Textbox(
|
175 |
-
lines=
|
176 |
label="Output",
|
177 |
interactive=False,
|
178 |
show_copy_button=True
|
179 |
)
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
187 |
|
188 |
|
189 |
input_.change(
|
@@ -206,7 +215,7 @@ def gradio_app():
|
|
206 |
clear_btn.click(
|
207 |
fn=clear,
|
208 |
inputs=[],
|
209 |
-
outputs=[input_, output, context_evaluation] + parameters_compontents,
|
210 |
queue=False,
|
211 |
api_name=False
|
212 |
)
|
@@ -214,7 +223,7 @@ def gradio_app():
|
|
214 |
submit_btn.click(
|
215 |
fn=submit_input,
|
216 |
inputs=[input_]+ parameters_compontents,
|
217 |
-
outputs=[output,context_evaluation],
|
218 |
api_name="get-results"
|
219 |
)
|
220 |
|
@@ -225,7 +234,7 @@ def gradio_app():
|
|
225 |
["""Què és l'EADOP (Entitat Autònoma del Diari Oficial i de Publicacions)?"""],
|
226 |
],
|
227 |
inputs=input_,
|
228 |
-
outputs=[output,context_evaluation],
|
229 |
fn=submit_input,
|
230 |
)
|
231 |
gr.Examples(
|
@@ -233,7 +242,7 @@ def gradio_app():
|
|
233 |
["""Què diu el decret sobre la senyalització de les begudes alcohòliques i el tabac a Catalunya?"""],
|
234 |
],
|
235 |
inputs=input_,
|
236 |
-
outputs=[output,context_evaluation],
|
237 |
fn=submit_input,
|
238 |
)
|
239 |
gr.Examples(
|
@@ -241,7 +250,7 @@ def gradio_app():
|
|
241 |
["""Com es pot inscriure una persona al Registre de catalans i catalanes residents a l'exterior?"""],
|
242 |
],
|
243 |
inputs=input_,
|
244 |
-
outputs=[output,context_evaluation],
|
245 |
fn=submit_input,
|
246 |
)
|
247 |
gr.Examples(
|
@@ -249,7 +258,7 @@ def gradio_app():
|
|
249 |
["""Quina és la finalitat del Servei Meterològic de Catalunya ?"""],
|
250 |
],
|
251 |
inputs=input_,
|
252 |
-
outputs=[output,context_evaluation],
|
253 |
fn=submit_input,
|
254 |
)
|
255 |
|
|
|
24 |
|
25 |
def generate(prompt, model_parameters):
|
26 |
try:
|
27 |
+
output, context, source = rag.get_response(prompt, model_parameters)
|
28 |
+
return output, context, source
|
29 |
except HTTPError as err:
|
30 |
if err.code == 400:
|
31 |
gr.Warning(
|
|
|
54 |
"TEMPERATURE": temperature
|
55 |
}
|
56 |
|
57 |
+
output, context, source = generate(input_, model_parameters)
|
58 |
+
sources_markup = ""
|
59 |
+
|
60 |
+
for url in source:
|
61 |
+
sources_markup += f'<a href="{url}" target="_blank">{url}</a><br>'
|
62 |
+
|
63 |
+
return output.strip(), sources_markup, context
|
64 |
|
65 |
|
66 |
def change_interactive(text):
|
|
|
75 |
None,
|
76 |
None,
|
77 |
None,
|
78 |
+
None,
|
79 |
gr.Slider(value=100),
|
80 |
gr.Slider(value=1.2),
|
81 |
gr.Slider(value=50),
|
|
|
178 |
|
179 |
with gr.Column(variant="panel"):
|
180 |
output = Textbox(
|
181 |
+
lines=10,
|
182 |
label="Output",
|
183 |
interactive=False,
|
184 |
show_copy_button=True
|
185 |
)
|
186 |
+
with gr.Accordion("Sources and context:", open=False):
|
187 |
+
source_context = gr.Markdown(
|
188 |
+
)
|
189 |
+
with gr.Accordion("See full context evaluation:", open=False):
|
190 |
+
context_evaluation = gr.Markdown(
|
191 |
+
# show_label=False,
|
192 |
+
# interactive=False,
|
193 |
+
# autoscroll=False,
|
194 |
+
# show_copy_button=True
|
195 |
+
)
|
196 |
|
197 |
|
198 |
input_.change(
|
|
|
215 |
clear_btn.click(
|
216 |
fn=clear,
|
217 |
inputs=[],
|
218 |
+
outputs=[input_, output, source_context, context_evaluation] + parameters_compontents,
|
219 |
queue=False,
|
220 |
api_name=False
|
221 |
)
|
|
|
223 |
submit_btn.click(
|
224 |
fn=submit_input,
|
225 |
inputs=[input_]+ parameters_compontents,
|
226 |
+
outputs=[output, source_context, context_evaluation],
|
227 |
api_name="get-results"
|
228 |
)
|
229 |
|
|
|
234 |
["""Què és l'EADOP (Entitat Autònoma del Diari Oficial i de Publicacions)?"""],
|
235 |
],
|
236 |
inputs=input_,
|
237 |
+
outputs=[output, source_context, context_evaluation],
|
238 |
fn=submit_input,
|
239 |
)
|
240 |
gr.Examples(
|
|
|
242 |
["""Què diu el decret sobre la senyalització de les begudes alcohòliques i el tabac a Catalunya?"""],
|
243 |
],
|
244 |
inputs=input_,
|
245 |
+
outputs=[output, source_context, context_evaluation],
|
246 |
fn=submit_input,
|
247 |
)
|
248 |
gr.Examples(
|
|
|
250 |
["""Com es pot inscriure una persona al Registre de catalans i catalanes residents a l'exterior?"""],
|
251 |
],
|
252 |
inputs=input_,
|
253 |
+
outputs=[output, source_context, context_evaluation],
|
254 |
fn=submit_input,
|
255 |
)
|
256 |
gr.Examples(
|
|
|
258 |
["""Quina és la finalitat del Servei Meterològic de Catalunya ?"""],
|
259 |
],
|
260 |
inputs=input_,
|
261 |
+
outputs=[output, source_context, context_evaluation],
|
262 |
fn=submit_input,
|
263 |
)
|
264 |
|