Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,12 @@ development_texts = [
|
|
59 |
# ------------------------------
|
60 |
# Text Splitting & Document Creation
|
61 |
# ------------------------------
|
62 |
-
splitter = RecursiveCharacterTextSplitter(
|
|
|
|
|
|
|
|
|
|
|
63 |
research_docs = splitter.create_documents(research_texts)
|
64 |
development_docs = splitter.create_documents(development_texts)
|
65 |
|
@@ -85,12 +90,27 @@ development_vectorstore = Chroma.from_documents(
|
|
85 |
collection_name="development_collection"
|
86 |
)
|
87 |
|
88 |
-
research_retriever = research_vectorstore.as_retriever()
|
89 |
-
development_retriever = development_vectorstore.as_retriever()
|
90 |
-
|
91 |
# ------------------------------
|
92 |
-
# Creating Retriever Tools
|
93 |
# ------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
research_tool = create_retriever_tool(
|
95 |
research_retriever,
|
96 |
"research_db_tool",
|
@@ -205,10 +225,20 @@ def generate(state: AgentState):
|
|
205 |
"Content-Type": "application/json"
|
206 |
}
|
207 |
|
208 |
-
prompt = f"""
|
209 |
Question: {question}
|
210 |
Documents: {docs}
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
"""
|
213 |
|
214 |
data = {
|
@@ -343,7 +373,7 @@ def process_question(user_question, app, config):
|
|
343 |
return events
|
344 |
|
345 |
# ------------------------------
|
346 |
-
# Streamlit App UI (Dark Theme)
|
347 |
# ------------------------------
|
348 |
def main():
|
349 |
st.set_page_config(
|
@@ -362,44 +392,81 @@ def main():
|
|
362 |
.stTextArea textarea {
|
363 |
background-color: #2d2d2d !important;
|
364 |
color: #ffffff !important;
|
|
|
365 |
}
|
366 |
|
367 |
.stButton > button {
|
368 |
background-color: #4CAF50;
|
369 |
color: white;
|
|
|
|
|
|
|
370 |
transition: all 0.3s;
|
|
|
371 |
}
|
372 |
|
373 |
.stButton > button:hover {
|
374 |
background-color: #45a049;
|
375 |
transform: scale(1.02);
|
|
|
376 |
}
|
377 |
|
378 |
.data-box {
|
|
|
|
|
|
|
379 |
background-color: #2d2d2d;
|
380 |
-
border-left:
|
|
|
|
|
|
|
|
|
381 |
}
|
382 |
|
383 |
.dev-box {
|
384 |
-
border-
|
385 |
}
|
386 |
|
387 |
.st-expander {
|
388 |
background-color: #2d2d2d;
|
389 |
border: 1px solid #3d3d3d;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
}
|
391 |
</style>
|
392 |
""", unsafe_allow_html=True)
|
393 |
|
394 |
with st.sidebar:
|
395 |
st.header("π Available Data")
|
|
|
396 |
st.subheader("Research Database")
|
397 |
for text in research_texts:
|
398 |
-
st.markdown(f'<div class="data-box research-box"
|
399 |
|
400 |
st.subheader("Development Database")
|
401 |
for text in development_texts:
|
402 |
-
st.markdown(f'<div class="data-box dev-box"
|
403 |
|
404 |
st.title("π€ AI Research & Development Assistant")
|
405 |
st.markdown("---")
|
@@ -421,17 +488,36 @@ def main():
|
|
421 |
if "Error" in content:
|
422 |
st.error(content)
|
423 |
elif "Results:" in content:
|
424 |
-
st.markdown("### π Retrieved Documents
|
425 |
-
|
426 |
-
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
elif 'generate' in event:
|
429 |
content = event['generate']['messages'][0].content
|
430 |
if "Error" in content:
|
431 |
st.error(content)
|
432 |
else:
|
433 |
-
st.markdown("### β¨ Final Answer
|
434 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
except Exception as e:
|
436 |
st.error(f"""
|
437 |
**Processing Error**
|
@@ -447,15 +533,21 @@ def main():
|
|
447 |
with col2:
|
448 |
st.markdown("""
|
449 |
### π― How to Use
|
450 |
-
1. Enter your question in the text box
|
451 |
-
2. Click the search button
|
452 |
-
3. Review processing steps
|
453 |
-
4.
|
454 |
|
455 |
### π‘ Example Questions
|
456 |
-
- What's new in
|
457 |
-
- How is Project
|
458 |
-
- Recent
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
""")
|
460 |
|
461 |
if __name__ == "__main__":
|
|
|
59 |
# ------------------------------
|
60 |
# Text Splitting & Document Creation
|
61 |
# ------------------------------
|
62 |
+
splitter = RecursiveCharacterTextSplitter(
|
63 |
+
chunk_size=300,
|
64 |
+
chunk_overlap=30,
|
65 |
+
separators=["\n\n", "\n", ". ", "! ", "? ", " "]
|
66 |
+
)
|
67 |
+
|
68 |
research_docs = splitter.create_documents(research_texts)
|
69 |
development_docs = splitter.create_documents(development_texts)
|
70 |
|
|
|
90 |
collection_name="development_collection"
|
91 |
)
|
92 |
|
|
|
|
|
|
|
93 |
# ------------------------------
|
94 |
+
# Creating Retriever Tools with MMR
|
95 |
# ------------------------------
|
96 |
+
research_retriever = research_vectorstore.as_retriever(
|
97 |
+
search_type="mmr",
|
98 |
+
search_kwargs={
|
99 |
+
'k': 3,
|
100 |
+
'fetch_k': 10,
|
101 |
+
'lambda_mult': 0.7
|
102 |
+
}
|
103 |
+
)
|
104 |
+
|
105 |
+
development_retriever = development_vectorstore.as_retriever(
|
106 |
+
search_type="mmr",
|
107 |
+
search_kwargs={
|
108 |
+
'k': 3,
|
109 |
+
'fetch_k': 10,
|
110 |
+
'lambda_mult': 0.7
|
111 |
+
}
|
112 |
+
)
|
113 |
+
|
114 |
research_tool = create_retriever_tool(
|
115 |
research_retriever,
|
116 |
"research_db_tool",
|
|
|
225 |
"Content-Type": "application/json"
|
226 |
}
|
227 |
|
228 |
+
prompt = f"""Analyze these research documents and provide structured insights:
|
229 |
Question: {question}
|
230 |
Documents: {docs}
|
231 |
+
|
232 |
+
Format your response with:
|
233 |
+
1. Key Findings section with bullet points
|
234 |
+
2. Technical Innovations section
|
235 |
+
3. Potential Applications
|
236 |
+
4. References to source documents (Doc1, Doc2, etc.)
|
237 |
+
|
238 |
+
Focus on:
|
239 |
+
- Distilling unique insights
|
240 |
+
- Connecting different research aspects
|
241 |
+
- Highlighting practical implications
|
242 |
"""
|
243 |
|
244 |
data = {
|
|
|
373 |
return events
|
374 |
|
375 |
# ------------------------------
|
376 |
+
# Streamlit App UI (Enhanced Dark Theme)
|
377 |
# ------------------------------
|
378 |
def main():
|
379 |
st.set_page_config(
|
|
|
392 |
.stTextArea textarea {
|
393 |
background-color: #2d2d2d !important;
|
394 |
color: #ffffff !important;
|
395 |
+
border: 1px solid #3d3d3d;
|
396 |
}
|
397 |
|
398 |
.stButton > button {
|
399 |
background-color: #4CAF50;
|
400 |
color: white;
|
401 |
+
border: none;
|
402 |
+
padding: 12px 28px;
|
403 |
+
border-radius: 6px;
|
404 |
transition: all 0.3s;
|
405 |
+
font-weight: 500;
|
406 |
}
|
407 |
|
408 |
.stButton > button:hover {
|
409 |
background-color: #45a049;
|
410 |
transform: scale(1.02);
|
411 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
412 |
}
|
413 |
|
414 |
.data-box {
|
415 |
+
padding: 18px;
|
416 |
+
margin: 12px 0;
|
417 |
+
border-radius: 8px;
|
418 |
background-color: #2d2d2d;
|
419 |
+
border-left: 4px solid;
|
420 |
+
}
|
421 |
+
|
422 |
+
.research-box {
|
423 |
+
border-color: #2196F3;
|
424 |
}
|
425 |
|
426 |
.dev-box {
|
427 |
+
border-color: #4CAF50;
|
428 |
}
|
429 |
|
430 |
.st-expander {
|
431 |
background-color: #2d2d2d;
|
432 |
border: 1px solid #3d3d3d;
|
433 |
+
border-radius: 6px;
|
434 |
+
margin: 16px 0;
|
435 |
+
}
|
436 |
+
|
437 |
+
.st-expander .streamlit-expanderHeader {
|
438 |
+
color: #ffffff !important;
|
439 |
+
font-weight: 500;
|
440 |
+
}
|
441 |
+
|
442 |
+
.stAlert {
|
443 |
+
background-color: #2d2d2d !important;
|
444 |
+
border: 1px solid #3d3d3d;
|
445 |
+
}
|
446 |
+
|
447 |
+
h1, h2, h3 {
|
448 |
+
color: #ffffff !important;
|
449 |
+
border-bottom: 2px solid #3d3d3d;
|
450 |
+
padding-bottom: 8px;
|
451 |
+
}
|
452 |
+
|
453 |
+
.stMarkdown {
|
454 |
+
color: #e0e0e0;
|
455 |
+
line-height: 1.6;
|
456 |
}
|
457 |
</style>
|
458 |
""", unsafe_allow_html=True)
|
459 |
|
460 |
with st.sidebar:
|
461 |
st.header("π Available Data")
|
462 |
+
|
463 |
st.subheader("Research Database")
|
464 |
for text in research_texts:
|
465 |
+
st.markdown(f'<div class="data-box research-box">{text}</div>', unsafe_allow_html=True)
|
466 |
|
467 |
st.subheader("Development Database")
|
468 |
for text in development_texts:
|
469 |
+
st.markdown(f'<div class="data-box dev-box">{text}</div>', unsafe_allow_html=True)
|
470 |
|
471 |
st.title("π€ AI Research & Development Assistant")
|
472 |
st.markdown("---")
|
|
|
488 |
if "Error" in content:
|
489 |
st.error(content)
|
490 |
elif "Results:" in content:
|
491 |
+
st.markdown("### π Retrieved Documents")
|
492 |
+
docs = content.split("Results:")[1].strip()
|
493 |
+
|
494 |
+
# Process and deduplicate documents
|
495 |
+
unique_docs = list({
|
496 |
+
doc.split('page_content=')[1].split(')')[0].strip("'")
|
497 |
+
for doc in docs.split("Document(")[1:]
|
498 |
+
})
|
499 |
+
|
500 |
+
for i, doc in enumerate(unique_docs, 1):
|
501 |
+
st.markdown(f"""
|
502 |
+
**Document {i}**
|
503 |
+
{doc}
|
504 |
+
""")
|
505 |
elif 'generate' in event:
|
506 |
content = event['generate']['messages'][0].content
|
507 |
if "Error" in content:
|
508 |
st.error(content)
|
509 |
else:
|
510 |
+
st.markdown("### β¨ Final Answer")
|
511 |
+
st.markdown(f"""
|
512 |
+
<div style='
|
513 |
+
background-color: #2d2d2d;
|
514 |
+
padding: 20px;
|
515 |
+
border-radius: 8px;
|
516 |
+
margin-top: 16px;
|
517 |
+
'>
|
518 |
+
{content}
|
519 |
+
</div>
|
520 |
+
""", unsafe_allow_html=True)
|
521 |
except Exception as e:
|
522 |
st.error(f"""
|
523 |
**Processing Error**
|
|
|
533 |
with col2:
|
534 |
st.markdown("""
|
535 |
### π― How to Use
|
536 |
+
1. **Enter** your question in the text box
|
537 |
+
2. **Click** the search button
|
538 |
+
3. **Review** processing steps
|
539 |
+
4. **Analyze** final structured answer
|
540 |
|
541 |
### π‘ Example Questions
|
542 |
+
- What's new in quantum machine learning?
|
543 |
+
- How is Project Y progressing?
|
544 |
+
- Recent breakthroughs in AI image recognition?
|
545 |
+
|
546 |
+
### π Search Features
|
547 |
+
- Automatic query optimization
|
548 |
+
- Technical document analysis
|
549 |
+
- Cross-project insights
|
550 |
+
- Source-aware reporting
|
551 |
""")
|
552 |
|
553 |
if __name__ == "__main__":
|