Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,8 @@ def paginar_frame(df):
|
|
27 |
cols = st.columns(N_cards_per_row, gap="large")
|
28 |
# draw the card
|
29 |
with cols[n_row%N_cards_per_row]:
|
|
|
|
|
30 |
st.caption(f"{row['feed'].strip()} - {row['seccion'].strip()} - {row['fecha'].strip()} ")
|
31 |
st.markdown(f"**{row['titulo'].strip()}**")
|
32 |
st.markdown(f"{row['resumen'].strip()}")
|
@@ -122,8 +124,12 @@ def main():
|
|
122 |
if ('?' in query):
|
123 |
st.write("Contestando a: ", query)
|
124 |
# Verificando cada resumen de los articulos como contexto a la pregunta
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
inputs = tokenizer(query, text, return_tensors='tf')
|
128 |
outputs = qa_model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'])
|
129 |
answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
|
@@ -131,10 +137,36 @@ def main():
|
|
131 |
predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
|
132 |
answer=tokenizer.decode(predict_answer_tokens)
|
133 |
if (len(answer)>0):
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
|
140 |
# Si se especificaron keywords
|
|
|
27 |
cols = st.columns(N_cards_per_row, gap="large")
|
28 |
# draw the card
|
29 |
with cols[n_row%N_cards_per_row]:
|
30 |
+
if (row['answer']):
|
31 |
+
st.info(row['answer'])
|
32 |
st.caption(f"{row['feed'].strip()} - {row['seccion'].strip()} - {row['fecha'].strip()} ")
|
33 |
st.markdown(f"**{row['titulo'].strip()}**")
|
34 |
st.markdown(f"{row['resumen'].strip()}")
|
|
|
124 |
if ('?' in query):
|
125 |
st.write("Contestando a: ", query)
|
126 |
# Verificando cada resumen de los articulos como contexto a la pregunta
|
127 |
+
cantidad_respuestas = 0
|
128 |
+
lista_noticias_respuestas = []
|
129 |
+
df_answer=df
|
130 |
+
df_answer['answer']=''
|
131 |
+
for i in range(len(df_answer)):
|
132 |
+
text=df_answer.loc[i, "resumen"]
|
133 |
inputs = tokenizer(query, text, return_tensors='tf')
|
134 |
outputs = qa_model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'])
|
135 |
answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
|
|
|
137 |
predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
|
138 |
answer=tokenizer.decode(predict_answer_tokens)
|
139 |
if (len(answer)>0):
|
140 |
+
cantidad_respuestas = cantidad_respuestas + 1
|
141 |
+
df_answer.loc[i, "answer"] = answer
|
142 |
+
lista_noticias_respuestas.append(df_answer.loc[i].to_frame().T)
|
143 |
+
|
144 |
+
df_noticias_respuestas=pd.concat(lista_noticias_respuestas)
|
145 |
+
batch_size = 5
|
146 |
+
pages = split_frame(df_noticias_respuestas, batch_size)
|
147 |
+
top_menu = st.columns(3)
|
148 |
+
|
149 |
+
pagination = st.container()
|
150 |
+
|
151 |
+
|
152 |
+
bottom_menu = st.columns((3))
|
153 |
+
|
154 |
+
with bottom_menu[2]:
|
155 |
+
total_pages = (ceil(cantidad_respuestas / batch_size) if ceil(cantidad_respuestas / batch_size) > 0 else 1)
|
156 |
+
current_page = st.number_input("Página", min_value=1, max_value=total_pages, step=1)
|
157 |
+
|
158 |
+
with bottom_menu[1]:
|
159 |
+
st.write("---")
|
160 |
+
st.markdown(f"Página **{current_page}** de **{total_pages}** ")
|
161 |
+
|
162 |
+
with top_menu[0]:
|
163 |
+
pagina_res_fin= batch_size*current_page if batch_size*current_page <= cantidad_respuestas else cantidad_respuestas
|
164 |
+
st.markdown(f"Respuestas **{(current_page*batch_size)-batch_size+1}-{pagina_res_fin}** de **{cantidad_respuestas}** ")
|
165 |
+
|
166 |
+
with pagination:
|
167 |
+
|
168 |
+
paginar_frame(pages[current_page - 1])
|
169 |
+
|
170 |
|
171 |
|
172 |
# Si se especificaron keywords
|