whitead commited on
Commit
771025f
1 Parent(s): bb05f0e

Added length and raw text

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -23,7 +23,7 @@ def validate_dataset(dataset, openapi):
23
  return "⚠️Waiting for documents and key..."
24
 
25
 
26
- def do_ask(question, button, openapi, dataset, progress=gr.Progress()):
27
  global docs
28
  docs_ready = dataset.iloc[-1, 0] != ""
29
  if button == "✨Ready✨" and type(openapi) is str and len(openapi) > 0 and docs_ready:
@@ -39,13 +39,17 @@ def do_ask(question, button, openapi, dataset, progress=gr.Progress()):
39
  key = row['citation string']
40
  docs.add(row['filepath'], row['citation string'], key=key)
41
  else:
42
- return ""
43
  progress(0, "Building Index...")
44
  docs._build_faiss_index()
45
  progress(0.25, "Querying...")
46
- result = docs.query(question)
47
  progress(1.0, "Done!")
48
- return result.formatted_answer, result.context
 
 
 
 
49
 
50
 
51
  with gr.Blocks() as demo:
@@ -86,6 +90,7 @@ with gr.Blocks() as demo:
86
  uploaded_files], outputs=[dataset])
87
  query = gr.Textbox(
88
  placeholder="Enter your question here...", label="Question")
 
89
  ask = gr.Button("Ask Question")
90
  gr.Markdown("## Answer")
91
  answer = gr.Markdown(label="Answer")
@@ -93,8 +98,13 @@ with gr.Blocks() as demo:
93
  gr.Markdown(
94
  "### Context\n\nThe following context was used to generate the answer:")
95
  context = gr.Markdown(label="Context")
 
 
 
 
 
96
  ask.click(fn=do_ask, inputs=[query, buildb,
97
- openai_api_key, dataset], outputs=[answer, context])
98
 
99
  demo.queue(concurrency_count=20)
100
  demo.launch(show_error=True)
 
23
  return "⚠️Waiting for documents and key..."
24
 
25
 
26
+ def do_ask(question, button, openapi, dataset, slider, progress=gr.Progress()):
27
  global docs
28
  docs_ready = dataset.iloc[-1, 0] != ""
29
  if button == "✨Ready✨" and type(openapi) is str and len(openapi) > 0 and docs_ready:
 
39
  key = row['citation string']
40
  docs.add(row['filepath'], row['citation string'], key=key)
41
  else:
42
+ return "", "", ""
43
  progress(0, "Building Index...")
44
  docs._build_faiss_index()
45
  progress(0.25, "Querying...")
46
+ result = docs.query(question, length_prompt=f'use {slider:d} words')
47
  progress(1.0, "Done!")
48
+ # format the passages
49
+ passages = ""
50
+ for i, (key, passage) in enumerate(result.passages.items()):
51
+ passages += f'{i+1}. {key}\n\n```{passage}```\n\n'
52
+ return result.formatted_answer, result.context, passages
53
 
54
 
55
  with gr.Blocks() as demo:
 
90
  uploaded_files], outputs=[dataset])
91
  query = gr.Textbox(
92
  placeholder="Enter your question here...", label="Question")
93
+ slider = gr.Slider(25, 200, value=100, step=5, label='answer length')
94
  ask = gr.Button("Ask Question")
95
  gr.Markdown("## Answer")
96
  answer = gr.Markdown(label="Answer")
 
98
  gr.Markdown(
99
  "### Context\n\nThe following context was used to generate the answer:")
100
  context = gr.Markdown(label="Context")
101
+
102
+ with gr.Accordion("Raw Text", open=False):
103
+ gr.Markdown(
104
+ "### Raw Text\n\nThe following raw text was used to generate the answer:")
105
+ passages = gr.Markdown(label="Passages")
106
  ask.click(fn=do_ask, inputs=[query, buildb,
107
+ openai_api_key, dataset, slider], outputs=[answer, context, passages])
108
 
109
  demo.queue(concurrency_count=20)
110
  demo.launch(show_error=True)