Update app.py
Browse files
app.py
CHANGED
|
@@ -35,19 +35,19 @@ def setup_generator(api_key):
|
|
| 35 |
return qa
|
| 36 |
|
| 37 |
def generate_text(api_key, query):
|
| 38 |
-
|
| 39 |
-
|
| 40 |
qa = setup_generator(api_key)
|
| 41 |
result = qa.run(query)
|
| 42 |
res = result["result"]
|
| 43 |
-
source = result["source_documents"]
|
| 44 |
-
formatted_text = '\n'.join(textwrap.wrap(res, width=
|
| 45 |
-
return formatted_text
|
| 46 |
|
| 47 |
iface = gr.Interface(
|
| 48 |
fn=generate_text,
|
| 49 |
inputs=[gr.inputs.Textbox(lines=1, placeholder="Input API Key..."),
|
| 50 |
-
gr.inputs.Textbox(lines=
|
| 51 |
-
outputs=gr.outputs.Textbox()
|
|
|
|
| 52 |
)
|
| 53 |
iface.launch()
|
|
|
|
|
|
| 35 |
return qa
|
| 36 |
|
| 37 |
def generate_text(api_key, query):
|
|
|
|
|
|
|
| 38 |
qa = setup_generator(api_key)
|
| 39 |
result = qa.run(query)
|
| 40 |
res = result["result"]
|
| 41 |
+
source = "\n".join([meta.metadata for meta result["source_documents"]])
|
| 42 |
+
formatted_text = '\n'.join(textwrap.wrap(res, width=90))
|
| 43 |
+
return formatted_text, source
|
| 44 |
|
| 45 |
iface = gr.Interface(
|
| 46 |
fn=generate_text,
|
| 47 |
inputs=[gr.inputs.Textbox(lines=1, placeholder="Input API Key..."),
|
| 48 |
+
gr.inputs.Textbox(lines=3, placeholder="Input Text...")],
|
| 49 |
+
outputs=[gr.outputs.Textbox(label="Generated Text"),
|
| 50 |
+
gr.outputs.Textbox(label="Source")]
|
| 51 |
)
|
| 52 |
iface.launch()
|
| 53 |
+
|