Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -43,14 +43,10 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
43 |
if not HF_TOKEN:
|
44 |
raise ValueError("HF_TOKEN not found in environment variables")
|
45 |
|
46 |
-
#
|
47 |
-
TITLE = "<h1
|
48 |
-
|
49 |
-
|
50 |
-
<p>Upload PDF or text files to get started!</p>
|
51 |
-
<p>After asking question wait for RAG system to get relevant nodes and pass to LLM</p>
|
52 |
-
</center>
|
53 |
-
"""
|
54 |
CSS = """
|
55 |
.upload-section {
|
56 |
max-width: 400px;
|
@@ -226,8 +222,8 @@ def create_or_update_index(files, request: gr.Request):
|
|
226 |
}
|
227 |
|
228 |
node_parser = HierarchicalNodeParser.from_defaults(
|
229 |
-
chunk_sizes=[2048, 512, 128],
|
230 |
-
chunk_overlap=20
|
231 |
)
|
232 |
logger.info(f"Parsing {len(new_documents)} documents into hierarchical nodes")
|
233 |
new_nodes = node_parser.get_nodes_from_documents(new_documents)
|
@@ -407,7 +403,6 @@ def stream_chat(
|
|
407 |
partial_response += new_text
|
408 |
updated_history[-1]["content"] = partial_response
|
409 |
yield updated_history
|
410 |
-
output_ids = global_tokenizer.encode(partial_response, return_tensors="pt")
|
411 |
yield updated_history
|
412 |
except GeneratorExit:
|
413 |
stop_event.set()
|
@@ -416,14 +411,14 @@ def stream_chat(
|
|
416 |
|
417 |
def create_demo():
|
418 |
with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
|
419 |
gr.HTML(TITLE)
|
420 |
-
gr.HTML(DESCRIPTION)
|
421 |
|
422 |
with gr.Row(elem_classes="main-container"):
|
423 |
with gr.Column(elem_classes="upload-section"):
|
424 |
file_upload = gr.File(
|
425 |
file_count="multiple",
|
426 |
-
label="Drag
|
427 |
file_types=[".pdf", ".txt"],
|
428 |
elem_id="file-upload"
|
429 |
)
|
@@ -446,7 +441,7 @@ def create_demo():
|
|
446 |
with gr.Column(elem_classes="chatbot-container"):
|
447 |
chatbot = gr.Chatbot(
|
448 |
height=500,
|
449 |
-
placeholder="Chat with your documents
|
450 |
show_label=False,
|
451 |
type="messages"
|
452 |
)
|
@@ -462,7 +457,7 @@ def create_demo():
|
|
462 |
|
463 |
with gr.Accordion("Advanced Settings", open=False):
|
464 |
system_prompt = gr.Textbox(
|
465 |
-
value="As a knowledgeable assistant,
|
466 |
label="System Prompt",
|
467 |
lines=3
|
468 |
)
|
@@ -472,7 +467,7 @@ def create_demo():
|
|
472 |
minimum=0,
|
473 |
maximum=1,
|
474 |
step=0.1,
|
475 |
-
value=0.9,
|
476 |
label="Temperature"
|
477 |
)
|
478 |
max_new_tokens = gr.Slider(
|
@@ -553,10 +548,9 @@ def create_demo():
|
|
553 |
],
|
554 |
outputs=chatbot
|
555 |
)
|
556 |
-
|
557 |
return demo
|
558 |
|
559 |
if __name__ == "__main__":
|
560 |
initialize_model_and_tokenizer()
|
561 |
demo = create_demo()
|
562 |
-
demo.launch()
|
|
|
43 |
if not HF_TOKEN:
|
44 |
raise ValueError("HF_TOKEN not found in environment variables")
|
45 |
|
46 |
+
# --- UI Settings ---
|
47 |
+
TITLE = "<h1 style='text-align:center; margin-bottom: 20px;'>Local RAG Llama 3.1 8B</h1>"
|
48 |
+
# Description 제거 (사용자 요청)
|
49 |
+
|
|
|
|
|
|
|
|
|
50 |
CSS = """
|
51 |
.upload-section {
|
52 |
max-width: 400px;
|
|
|
222 |
}
|
223 |
|
224 |
node_parser = HierarchicalNodeParser.from_defaults(
|
225 |
+
chunk_sizes=[2048, 512, 128],
|
226 |
+
chunk_overlap=20
|
227 |
)
|
228 |
logger.info(f"Parsing {len(new_documents)} documents into hierarchical nodes")
|
229 |
new_nodes = node_parser.get_nodes_from_documents(new_documents)
|
|
|
403 |
partial_response += new_text
|
404 |
updated_history[-1]["content"] = partial_response
|
405 |
yield updated_history
|
|
|
406 |
yield updated_history
|
407 |
except GeneratorExit:
|
408 |
stop_event.set()
|
|
|
411 |
|
412 |
def create_demo():
|
413 |
with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
414 |
+
# Title only
|
415 |
gr.HTML(TITLE)
|
|
|
416 |
|
417 |
with gr.Row(elem_classes="main-container"):
|
418 |
with gr.Column(elem_classes="upload-section"):
|
419 |
file_upload = gr.File(
|
420 |
file_count="multiple",
|
421 |
+
label="Drag & Drop PDF/TXT Files Here",
|
422 |
file_types=[".pdf", ".txt"],
|
423 |
elem_id="file-upload"
|
424 |
)
|
|
|
441 |
with gr.Column(elem_classes="chatbot-container"):
|
442 |
chatbot = gr.Chatbot(
|
443 |
height=500,
|
444 |
+
placeholder="Chat with your documents...",
|
445 |
show_label=False,
|
446 |
type="messages"
|
447 |
)
|
|
|
457 |
|
458 |
with gr.Accordion("Advanced Settings", open=False):
|
459 |
system_prompt = gr.Textbox(
|
460 |
+
value="As a knowledgeable assistant, provide detailed answers using the relevant information from all uploaded documents.",
|
461 |
label="System Prompt",
|
462 |
lines=3
|
463 |
)
|
|
|
467 |
minimum=0,
|
468 |
maximum=1,
|
469 |
step=0.1,
|
470 |
+
value=0.9,
|
471 |
label="Temperature"
|
472 |
)
|
473 |
max_new_tokens = gr.Slider(
|
|
|
548 |
],
|
549 |
outputs=chatbot
|
550 |
)
|
|
|
551 |
return demo
|
552 |
|
553 |
if __name__ == "__main__":
|
554 |
initialize_model_and_tokenizer()
|
555 |
demo = create_demo()
|
556 |
+
demo.launch()
|