Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ llm_models = [
|
|
| 17 |
"meta-llama/Meta-Llama-3-8B-Instruct",
|
| 18 |
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 19 |
"tiiuae/falcon-7b-instruct",
|
|
|
|
| 20 |
# "NousResearch/Yarn-Mistral-7b-64k", ## 14GB>10GB
|
| 21 |
# "impira/layoutlm-document-qa", ## ERR
|
| 22 |
# "Qwen/Qwen1.5-7B", ## 15GB
|
|
@@ -39,7 +40,6 @@ llm_models = [
|
|
| 39 |
embed_models = [
|
| 40 |
"BAAI/bge-small-en-v1.5", # 33.4M
|
| 41 |
"NeuML/pubmedbert-base-embeddings",
|
| 42 |
-
"sentence-transformers/all-mpnet-base-v2", # 109M
|
| 43 |
"BAAI/llm-embedder", # 109M
|
| 44 |
"BAAI/bge-large-en" # 335M
|
| 45 |
]
|
|
@@ -108,7 +108,7 @@ def respond(message, history):
|
|
| 108 |
llm = HuggingFaceInferenceAPI(
|
| 109 |
model_name=selected_llm_model_name,
|
| 110 |
contextWindow=8192, # Context window size (typically max length of the model)
|
| 111 |
-
maxTokens=
|
| 112 |
temperature=0.3, # Lower temperature for more focused answers (0.2-0.4 for factual info)
|
| 113 |
topP=0.9, # Top-p sampling to control diversity while retaining quality
|
| 114 |
frequencyPenalty=0.5, # Slight penalty to avoid repetition
|
|
@@ -120,8 +120,8 @@ def respond(message, history):
|
|
| 120 |
query_engine = vector_index.as_query_engine(llm=llm)
|
| 121 |
bot_message = query_engine.query(message)
|
| 122 |
|
| 123 |
-
print(f"\n{datetime.now()}:{selected_llm_model_name}
|
| 124 |
-
return f"{selected_llm_model_name}:\n
|
| 125 |
except Exception as e:
|
| 126 |
if str(e) == "'NoneType' object has no attribute 'as_query_engine'":
|
| 127 |
return "Please upload a file."
|
|
@@ -144,14 +144,16 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")]),
|
|
| 144 |
gr.Markdown(md.description)
|
| 145 |
|
| 146 |
with gr.TabItem("DocBot"):
|
|
|
|
|
|
|
| 147 |
with gr.Row():
|
| 148 |
with gr.Column(scale=1):
|
| 149 |
file_input = gr.File(file_count="single", type='filepath', label="Step-1: Upload document")
|
| 150 |
-
gr.Markdown("Dont know what to select check out in Intro tab")
|
| 151 |
embed_model_dropdown = gr.Dropdown(embed_models, label="Step-2: Select Embedding", interactive=True)
|
| 152 |
with gr.Row():
|
| 153 |
-
clear = gr.ClearButton()
|
| 154 |
btn = gr.Button("Submit", variant='primary')
|
|
|
|
| 155 |
output = gr.Text(label='Vector Index')
|
| 156 |
llm_model_dropdown = gr.Dropdown(llm_models, label="Step-3: Select LLM", interactive=True)
|
| 157 |
with gr.Column(scale=3):
|
|
|
|
| 17 |
"meta-llama/Meta-Llama-3-8B-Instruct",
|
| 18 |
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 19 |
"tiiuae/falcon-7b-instruct",
|
| 20 |
+
# "mistralai/Mixtral-8x22B-Instruct-v0.1", ## 281GB>10GB
|
| 21 |
# "NousResearch/Yarn-Mistral-7b-64k", ## 14GB>10GB
|
| 22 |
# "impira/layoutlm-document-qa", ## ERR
|
| 23 |
# "Qwen/Qwen1.5-7B", ## 15GB
|
|
|
|
| 40 |
embed_models = [
|
| 41 |
"BAAI/bge-small-en-v1.5", # 33.4M
|
| 42 |
"NeuML/pubmedbert-base-embeddings",
|
|
|
|
| 43 |
"BAAI/llm-embedder", # 109M
|
| 44 |
"BAAI/bge-large-en" # 335M
|
| 45 |
]
|
|
|
|
| 108 |
llm = HuggingFaceInferenceAPI(
|
| 109 |
model_name=selected_llm_model_name,
|
| 110 |
contextWindow=8192, # Context window size (typically max length of the model)
|
| 111 |
+
maxTokens=1024, # Tokens per response generation (512-1024 works well for detailed answers)
|
| 112 |
temperature=0.3, # Lower temperature for more focused answers (0.2-0.4 for factual info)
|
| 113 |
topP=0.9, # Top-p sampling to control diversity while retaining quality
|
| 114 |
frequencyPenalty=0.5, # Slight penalty to avoid repetition
|
|
|
|
| 120 |
query_engine = vector_index.as_query_engine(llm=llm)
|
| 121 |
bot_message = query_engine.query(message)
|
| 122 |
|
| 123 |
+
print(f"\n{datetime.now()}:{selected_llm_model_name}:: {message} --> {str(bot_message)}\n")
|
| 124 |
+
return f"{selected_llm_model_name}:\n{str(bot_message)}"
|
| 125 |
except Exception as e:
|
| 126 |
if str(e) == "'NoneType' object has no attribute 'as_query_engine'":
|
| 127 |
return "Please upload a file."
|
|
|
|
| 144 |
gr.Markdown(md.description)
|
| 145 |
|
| 146 |
with gr.TabItem("DocBot"):
|
| 147 |
+
with gr.Accordion("=== IMPORTANT: READ ME FIRST ===", open=False):
|
| 148 |
+
guid = gr.Markdown(md.guide)
|
| 149 |
with gr.Row():
|
| 150 |
with gr.Column(scale=1):
|
| 151 |
file_input = gr.File(file_count="single", type='filepath', label="Step-1: Upload document")
|
| 152 |
+
# gr.Markdown("Dont know what to select check out in Intro tab")
|
| 153 |
embed_model_dropdown = gr.Dropdown(embed_models, label="Step-2: Select Embedding", interactive=True)
|
| 154 |
with gr.Row():
|
|
|
|
| 155 |
btn = gr.Button("Submit", variant='primary')
|
| 156 |
+
clear = gr.ClearButton()
|
| 157 |
output = gr.Text(label='Vector Index')
|
| 158 |
llm_model_dropdown = gr.Dropdown(llm_models, label="Step-3: Select LLM", interactive=True)
|
| 159 |
with gr.Column(scale=3):
|