Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +90 -2
src/streamlit_app.py
CHANGED
|
@@ -24,7 +24,7 @@ st.set_page_config(
|
|
| 24 |
)
|
| 25 |
|
| 26 |
COLLECTION_NAME = "math_knowledge_base"
|
| 27 |
-
DATASET_REPO = "
|
| 28 |
|
| 29 |
# ============================================================================
|
| 30 |
# AVAILABLE EMBEDDING MODELS
|
|
@@ -782,4 +782,92 @@ with tab2:
|
|
| 782 |
|
| 783 |
with st.spinner("Generating solution..."):
|
| 784 |
|
| 785 |
-
context = "\n\n".join([r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
COLLECTION_NAME = "math_knowledge_base"
|
| 27 |
+
DATASET_REPO = "Hebaelsayed/math-ai-documents"
|
| 28 |
|
| 29 |
# ============================================================================
|
| 30 |
# AVAILABLE EMBEDDING MODELS
|
|
|
|
| 782 |
|
| 783 |
with st.spinner("Generating solution..."):
|
| 784 |
|
| 785 |
+
context = "\n\n".join([r.payload['content'] for r in results])
|
| 786 |
+
|
| 787 |
+
prompt = f"""Solve this problem using references.
|
| 788 |
+
|
| 789 |
+
PROBLEM: {problem}
|
| 790 |
+
|
| 791 |
+
REFERENCES: {context}
|
| 792 |
+
|
| 793 |
+
DETAIL: {detail}
|
| 794 |
+
|
| 795 |
+
FORMAT:
|
| 796 |
+
## SOLUTION
|
| 797 |
+
[Steps]
|
| 798 |
+
|
| 799 |
+
## REASONING
|
| 800 |
+
[Why this approach]
|
| 801 |
+
|
| 802 |
+
## REFERENCES
|
| 803 |
+
[Which sources helped]"""
|
| 804 |
+
|
| 805 |
+
try:
|
| 806 |
+
message = claude.messages.create(
|
| 807 |
+
model="claude-sonnet-4-20250514",
|
| 808 |
+
max_tokens=4000,
|
| 809 |
+
messages=[{"role": "user", "content": prompt}]
|
| 810 |
+
)
|
| 811 |
+
|
| 812 |
+
st.markdown("---")
|
| 813 |
+
st.markdown(message.content[0].text)
|
| 814 |
+
|
| 815 |
+
st.download_button(
|
| 816 |
+
"📥 Download Solution",
|
| 817 |
+
message.content[0].text,
|
| 818 |
+
file_name=f"solution_{int(time.time())}.md"
|
| 819 |
+
)
|
| 820 |
+
|
| 821 |
+
except Exception as e:
|
| 822 |
+
st.error(f"Error: {e}")
|
| 823 |
+
|
| 824 |
+
# ============================================================================
|
| 825 |
+
# TAB 3: STATISTICS
|
| 826 |
+
# ============================================================================
|
| 827 |
+
|
| 828 |
+
with tab3:
|
| 829 |
+
|
| 830 |
+
st.title("📈 Statistics & Analytics")
|
| 831 |
+
|
| 832 |
+
try:
|
| 833 |
+
sample = qdrant.scroll(
|
| 834 |
+
collection_name=COLLECTION_NAME,
|
| 835 |
+
limit=1000,
|
| 836 |
+
with_payload=True,
|
| 837 |
+
with_vectors=False
|
| 838 |
+
)
|
| 839 |
+
|
| 840 |
+
if sample and sample[0]:
|
| 841 |
+
types = {}
|
| 842 |
+
sources = set()
|
| 843 |
+
|
| 844 |
+
for point in sample[0]:
|
| 845 |
+
src_type = point.payload.get('source_type', 'unknown')
|
| 846 |
+
types[src_type] = types.get(src_type, 0) + 1
|
| 847 |
+
sources.add(point.payload.get('source_name', 'Unknown'))
|
| 848 |
+
|
| 849 |
+
col1, col2, col3 = st.columns(3)
|
| 850 |
+
|
| 851 |
+
with col1:
|
| 852 |
+
st.metric("Total Vectors", get_vector_count(qdrant))
|
| 853 |
+
|
| 854 |
+
with col2:
|
| 855 |
+
st.metric("Unique Sources", len(sources))
|
| 856 |
+
|
| 857 |
+
with col3:
|
| 858 |
+
st.metric("Document Types", len(types))
|
| 859 |
+
|
| 860 |
+
st.subheader("Distribution by Type")
|
| 861 |
+
for doc_type, count in sorted(types.items()):
|
| 862 |
+
pct = count / sum(types.values()) * 100
|
| 863 |
+
st.progress(count / sum(types.values()), text=f"{doc_type}: {count} ({pct:.1f}%)")
|
| 864 |
+
|
| 865 |
+
st.subheader("All Sources")
|
| 866 |
+
for src in sorted(sources):
|
| 867 |
+
st.caption(f"• {src}")
|
| 868 |
+
|
| 869 |
+
except Exception as e:
|
| 870 |
+
st.error(f"Error: {e}")
|
| 871 |
+
|
| 872 |
+
st.sidebar.markdown("---")
|
| 873 |
+
st.sidebar.caption("v2.0 - Production")
|