| """The front door: a Gradio chat box for asking questions about your documents.""" | |
| import gradio as gr | |
| from generate import answer | |
| from ingest import ingest | |
| def setup(): | |
| """Load and index the documents once when the app starts.""" | |
| count = ingest() | |
| return f"Indexed {count} documents." | |
| def on_ask(question): | |
| return answer(question) | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Ask my documents") | |
| status = gr.Markdown(setup()) | |
| question = gr.Textbox(label="Your question") | |
| output = gr.Markdown() | |
| question.submit(on_ask, inputs=question, outputs=output) | |
| if __name__ == "__main__": | |
| demo.launch() | |