milyiyo commited on
Commit
941bfc4
·
1 Parent(s): 289e5ef

Debug error with gradio

Browse files
Files changed (2) hide show
  1. app.py +4 -3
  2. functions.py +7 -3
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
 
3
- from functions import extract_text, summarize_text, generate_question, get_answer_context, answer_question
4
 
5
 
6
  def update(name='default text'):
@@ -18,6 +18,8 @@ with gr.Blocks() as demo:
18
  show_label=False)
19
  btn_extract_text = gr.Button("Extraer texto")
20
  out_url_text = gr.Textbox(label="Texto extraído")
 
 
21
  btn_extract_text.click(
22
  fn=extract_text, inputs=inp_url, outputs=out_url_text)
23
 
@@ -55,7 +57,6 @@ with gr.Blocks() as demo:
55
  show_label=False)
56
  btn_qna = gr.Button("Responder")
57
  out_qna = gr.Textbox(show_label=False)
58
- btn_qna.click(fn=answer_question,
59
- inputs=[out_url_text, inp_qna], outputs=out_qna)
60
 
61
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ from functions import extract_text, summarize_text, generate_question, get_answer_context, answer_question, store_text_changes
4
 
5
 
6
  def update(name='default text'):
 
18
  show_label=False)
19
  btn_extract_text = gr.Button("Extraer texto")
20
  out_url_text = gr.Textbox(label="Texto extraído")
21
+ out_url_text.change(fn=store_text_changes,
22
+ show_progress=False, status_tracker=None)
23
  btn_extract_text.click(
24
  fn=extract_text, inputs=inp_url, outputs=out_url_text)
25
 
 
57
  show_label=False)
58
  btn_qna = gr.Button("Responder")
59
  out_qna = gr.Textbox(show_label=False)
60
+ btn_qna.click(fn=answer_question, inputs=inp_qna, outputs=out_qna)
 
61
 
62
  demo.launch()
functions.py CHANGED
@@ -17,9 +17,13 @@ device = 'cuda'
17
 
18
  shared = {
19
  'answer_context': None,
20
- 'embeddings_dataset': None
 
21
  }
22
 
 
 
 
23
 
24
  def get_nearest_examples(question: str, k: int):
25
  print(['get_nearest_examples', 'start'])
@@ -116,8 +120,8 @@ def get_answer_context():
116
  return shared['answer_context']
117
 
118
 
119
- def answer_question(full_text: str, question: str):
120
- return ', '.join([len(full_text), len(question)])
121
  print(['answer_question', 'start'])
122
  if not shared['embeddings_dataset']:
123
  build_faiss_index(full_text)
 
17
 
18
  shared = {
19
  'answer_context': None,
20
+ 'embeddings_dataset': None,
21
+ 'base_text': None,
22
  }
23
 
24
+ def store_text_changes(text):
25
+ shared['base_text'] = text
26
+
27
 
28
  def get_nearest_examples(question: str, k: int):
29
  print(['get_nearest_examples', 'start'])
 
120
  return shared['answer_context']
121
 
122
 
123
+ def answer_question(question: str):
124
+ return ', '.join([len(shared['base_text']), len(question)])
125
  print(['answer_question', 'start'])
126
  if not shared['embeddings_dataset']:
127
  build_faiss_index(full_text)