Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import base64
|
|
11 |
# Load environment variables
|
12 |
load_dotenv()
|
13 |
|
14 |
-
#
|
15 |
selected_llm_model_name = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
16 |
selected_embed_model_name = "BAAI/bge-small-en-v1.5"
|
17 |
vector_index = None
|
@@ -19,19 +19,9 @@ vector_index = None
|
|
19 |
# Initialize the parser
|
20 |
parser = LlamaParse(api_key=os.getenv("LLAMA_INDEX_API"), result_type='markdown')
|
21 |
file_extractor = {
|
22 |
-
'.pdf': parser,
|
23 |
-
'.
|
24 |
-
'.
|
25 |
-
'.txt': parser,
|
26 |
-
'.csv': parser,
|
27 |
-
'.xlsx': parser,
|
28 |
-
'.pptx': parser,
|
29 |
-
'.html': parser,
|
30 |
-
'.jpg': parser,
|
31 |
-
'.jpeg': parser,
|
32 |
-
'.png': parser,
|
33 |
-
'.webp': parser,
|
34 |
-
'.svg': parser,
|
35 |
}
|
36 |
|
37 |
# File processing function
|
@@ -43,7 +33,7 @@ def load_files(file_path: str):
|
|
43 |
vector_index = VectorStoreIndex.from_documents(document, embed_model=embed_model)
|
44 |
print(f"Parsing done for {file_path}")
|
45 |
filename = os.path.basename(file_path)
|
46 |
-
return f"File upload status:
|
47 |
except Exception as e:
|
48 |
return f"An error occurred: {e}"
|
49 |
|
@@ -52,13 +42,8 @@ def respond(message, history):
|
|
52 |
try:
|
53 |
llm = HuggingFaceInferenceAPI(
|
54 |
model_name=selected_llm_model_name,
|
55 |
-
contextWindow=8192,
|
56 |
-
|
57 |
-
temperature=0.3,
|
58 |
-
topP=0.9,
|
59 |
-
frequencyPenalty=0.5,
|
60 |
-
presencePenalty=0.5,
|
61 |
-
token=os.getenv("TOKEN")
|
62 |
)
|
63 |
query_engine = vector_index.as_query_engine(llm=llm)
|
64 |
bot_message = query_engine.query(message)
|
@@ -70,25 +55,23 @@ def respond(message, history):
|
|
70 |
return f"An error occurred: {e}"
|
71 |
|
72 |
# UI Setup
|
73 |
-
with gr.Blocks(theme=gr.themes.
|
74 |
gr.Markdown("# DocBot📄🤖")
|
75 |
with gr.Row():
|
76 |
with gr.Column(scale=1):
|
77 |
-
file_input = gr.File(file_count="single", type='filepath', label="Upload
|
78 |
btn = gr.Button("Submit", variant='primary')
|
79 |
clear = gr.ClearButton()
|
80 |
-
output = gr.Text(label='File
|
81 |
with gr.Column(scale=3):
|
82 |
gr.ChatInterface(
|
83 |
fn=respond,
|
84 |
chatbot=gr.Chatbot(height=500),
|
85 |
-
theme="
|
86 |
show_progress='full',
|
87 |
textbox=gr.Textbox(placeholder="Ask me questions on the uploaded document!", container=False)
|
88 |
)
|
89 |
-
|
90 |
-
# Set up Gradio interactions
|
91 |
-
btn.click(fn=load_files, inputs=file_input, outputs=output)
|
92 |
clear.click(lambda: [None] * 2, outputs=[file_input, output])
|
93 |
|
94 |
# Launch the demo
|
|
|
11 |
# Load environment variables
|
12 |
load_dotenv()
|
13 |
|
14 |
+
# Default models
|
15 |
selected_llm_model_name = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
16 |
selected_embed_model_name = "BAAI/bge-small-en-v1.5"
|
17 |
vector_index = None
|
|
|
19 |
# Initialize the parser
|
20 |
parser = LlamaParse(api_key=os.getenv("LLAMA_INDEX_API"), result_type='markdown')
|
21 |
file_extractor = {
|
22 |
+
'.pdf': parser, '.docx': parser, '.doc': parser, '.txt': parser,
|
23 |
+
'.csv': parser, '.xlsx': parser, '.pptx': parser, '.html': parser,
|
24 |
+
'.jpg': parser, '.jpeg': parser, '.png': parser, '.webp': parser, '.svg': parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
|
27 |
# File processing function
|
|
|
33 |
vector_index = VectorStoreIndex.from_documents(document, embed_model=embed_model)
|
34 |
print(f"Parsing done for {file_path}")
|
35 |
filename = os.path.basename(file_path)
|
36 |
+
return f"File upload status: Ready to write ({filename})"
|
37 |
except Exception as e:
|
38 |
return f"An error occurred: {e}"
|
39 |
|
|
|
42 |
try:
|
43 |
llm = HuggingFaceInferenceAPI(
|
44 |
model_name=selected_llm_model_name,
|
45 |
+
contextWindow=8192, maxTokens=1024, temperature=0.3, topP=0.9,
|
46 |
+
frequencyPenalty=0.5, presencePenalty=0.5, token=os.getenv("TOKEN")
|
|
|
|
|
|
|
|
|
|
|
47 |
)
|
48 |
query_engine = vector_index.as_query_engine(llm=llm)
|
49 |
bot_message = query_engine.query(message)
|
|
|
55 |
return f"An error occurred: {e}"
|
56 |
|
57 |
# UI Setup
|
58 |
+
with gr.Blocks(theme=gr.themes.Light(font=[gr.themes.GoogleFont("Roboto Mono")]), css='footer {visibility: hidden}') as demo:
|
59 |
gr.Markdown("# DocBot📄🤖")
|
60 |
with gr.Row():
|
61 |
with gr.Column(scale=1):
|
62 |
+
file_input = gr.File(file_count="single", type='filepath', label="Upload Document")
|
63 |
btn = gr.Button("Submit", variant='primary')
|
64 |
clear = gr.ClearButton()
|
65 |
+
output = gr.Text(label='File Upload Status')
|
66 |
with gr.Column(scale=3):
|
67 |
gr.ChatInterface(
|
68 |
fn=respond,
|
69 |
chatbot=gr.Chatbot(height=500),
|
70 |
+
theme="light",
|
71 |
show_progress='full',
|
72 |
textbox=gr.Textbox(placeholder="Ask me questions on the uploaded document!", container=False)
|
73 |
)
|
74 |
+
btn.click(fn=load_files, inputs=[file_input], outputs=output)
|
|
|
|
|
75 |
clear.click(lambda: [None] * 2, outputs=[file_input, output])
|
76 |
|
77 |
# Launch the demo
|