Spaces:
Running
Running
make sure user specifies at least one source (#16)
Browse files- cfg.py +1 -1
- gradio_app.py +24 -13
cfg.py
CHANGED
|
@@ -28,7 +28,7 @@ logger.info(f"{DEEPLAKE_DATASET_PATH=}")
|
|
| 28 |
|
| 29 |
example_questions = [
|
| 30 |
"What is the LLama model?",
|
| 31 |
-
"What is a
|
| 32 |
"What is an embedding?",
|
| 33 |
]
|
| 34 |
|
|
|
|
| 28 |
|
| 29 |
example_questions = [
|
| 30 |
"What is the LLama model?",
|
| 31 |
+
"What is a Large Language Model?",
|
| 32 |
"What is an embedding?",
|
| 33 |
]
|
| 34 |
|
gradio_app.py
CHANGED
|
@@ -5,6 +5,8 @@ from typing import Optional
|
|
| 5 |
import gradio as gr
|
| 6 |
import pandas as pd
|
| 7 |
|
|
|
|
|
|
|
| 8 |
import cfg
|
| 9 |
from cfg import setup_buster
|
| 10 |
|
|
@@ -19,14 +21,6 @@ logging.basicConfig(level=logging.INFO)
|
|
| 19 |
AVAILABLE_SOURCES = ["towardsai", "wikipedia", "langchain_course"]
|
| 20 |
|
| 21 |
|
| 22 |
-
def check_auth(username: str, password: str) -> bool:
|
| 23 |
-
valid_user = username == cfg.USERNAME
|
| 24 |
-
valid_password = password == cfg.PASSWORD
|
| 25 |
-
is_auth = valid_user and valid_password
|
| 26 |
-
logger.info(f"Log-in attempted by {username=}. {is_auth=}")
|
| 27 |
-
return is_auth
|
| 28 |
-
|
| 29 |
-
|
| 30 |
def format_sources(matched_documents: pd.DataFrame) -> str:
|
| 31 |
if len(matched_documents) == 0:
|
| 32 |
return ""
|
|
@@ -67,10 +61,23 @@ def user(user_input, history):
|
|
| 67 |
return "", history + [[user_input, None]]
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def get_answer(history, sources: Optional[list[str]] = None):
|
| 71 |
user_input = history[-1][0]
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
history[-1][1] = ""
|
| 76 |
|
|
@@ -80,7 +87,7 @@ def get_answer(history, sources: Optional[list[str]] = None):
|
|
| 80 |
yield history, completion
|
| 81 |
|
| 82 |
|
| 83 |
-
block = gr.Blocks(
|
| 84 |
|
| 85 |
with block:
|
| 86 |
with gr.Row():
|
|
@@ -88,8 +95,11 @@ with block:
|
|
| 88 |
"<h3><center>Buster 🤖: A Question-Answering Bot for your documentation</center></h3>"
|
| 89 |
)
|
| 90 |
|
| 91 |
-
source_selection = gr.
|
| 92 |
-
choices=AVAILABLE_SOURCES,
|
|
|
|
|
|
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
chatbot = gr.Chatbot()
|
|
@@ -108,7 +118,8 @@ with block:
|
|
| 108 |
)
|
| 109 |
|
| 110 |
gr.Markdown(
|
| 111 |
-
"This application uses
|
|
|
|
| 112 |
)
|
| 113 |
|
| 114 |
response = gr.State()
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import pandas as pd
|
| 7 |
|
| 8 |
+
from buster.completers import Completion
|
| 9 |
+
|
| 10 |
import cfg
|
| 11 |
from cfg import setup_buster
|
| 12 |
|
|
|
|
| 21 |
AVAILABLE_SOURCES = ["towardsai", "wikipedia", "langchain_course"]
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def format_sources(matched_documents: pd.DataFrame) -> str:
|
| 25 |
if len(matched_documents) == 0:
|
| 26 |
return ""
|
|
|
|
| 61 |
return "", history + [[user_input, None]]
|
| 62 |
|
| 63 |
|
| 64 |
+
def get_empty_source_completion(user_input):
|
| 65 |
+
return Completion(
|
| 66 |
+
user_input=user_input,
|
| 67 |
+
answer_text="You have to select at least one source from the dropdown menu.",
|
| 68 |
+
matched_documents=pd.DataFrame(),
|
| 69 |
+
error=False,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
def get_answer(history, sources: Optional[list[str]] = None):
|
| 74 |
user_input = history[-1][0]
|
| 75 |
|
| 76 |
+
if len(sources) == 0:
|
| 77 |
+
completion = get_empty_source_completion(user_input)
|
| 78 |
+
|
| 79 |
+
else:
|
| 80 |
+
completion = buster.process_input(user_input, sources=sources)
|
| 81 |
|
| 82 |
history[-1][1] = ""
|
| 83 |
|
|
|
|
| 87 |
yield history, completion
|
| 88 |
|
| 89 |
|
| 90 |
+
block = gr.Blocks()
|
| 91 |
|
| 92 |
with block:
|
| 93 |
with gr.Row():
|
|
|
|
| 95 |
"<h3><center>Buster 🤖: A Question-Answering Bot for your documentation</center></h3>"
|
| 96 |
)
|
| 97 |
|
| 98 |
+
source_selection = gr.Dropdown(
|
| 99 |
+
choices=AVAILABLE_SOURCES,
|
| 100 |
+
label="Select Sources",
|
| 101 |
+
value=AVAILABLE_SOURCES,
|
| 102 |
+
multiselect=True,
|
| 103 |
)
|
| 104 |
|
| 105 |
chatbot = gr.Chatbot()
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
gr.Markdown(
|
| 121 |
+
"This application uses ChatGPT to search the docs for relevant info and answer questions. "
|
| 122 |
+
"\n\n### Powered by [Buster 🤖](www.github.com/jerpint/buster)"
|
| 123 |
)
|
| 124 |
|
| 125 |
response = gr.State()
|