Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -124,7 +124,15 @@ def load_document_and_cache(file_path):
|
|
| 124 |
return None, None, None
|
| 125 |
|
| 126 |
# ==============================
|
| 127 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
if uploaded_file:
|
| 129 |
# Generate unique temp filename
|
| 130 |
temp_file_path = f"temp_doc_{uuid.uuid4().hex}.txt"
|
|
@@ -134,10 +142,14 @@ if uploaded_file:
|
|
| 134 |
# Process document with token limit
|
| 135 |
cache, origin_len, doc_text = load_document_and_cache(temp_file_path)
|
| 136 |
|
| 137 |
-
# Show token count
|
| 138 |
with st.expander("π Document Preview"):
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
return None, None, None
|
| 125 |
|
| 126 |
# ==============================
|
| 127 |
+
# ==============================
|
| 128 |
+
# Main Streamlit UI and Workflow (updated)
|
| 129 |
+
# ==============================
|
| 130 |
+
|
| 131 |
+
st.title("π DeepSeek QA: Optimized Caching Dashboard")
|
| 132 |
+
|
| 133 |
+
# File uploader moved HERE
|
| 134 |
+
uploaded_file = st.file_uploader("π Upload your document (.txt)", type="txt")
|
| 135 |
+
|
| 136 |
if uploaded_file:
|
| 137 |
# Generate unique temp filename
|
| 138 |
temp_file_path = f"temp_doc_{uuid.uuid4().hex}.txt"
|
|
|
|
| 142 |
# Process document with token limit
|
| 143 |
cache, origin_len, doc_text = load_document_and_cache(temp_file_path)
|
| 144 |
|
| 145 |
+
# Show document preview with token count
|
| 146 |
with st.expander("π Document Preview"):
|
| 147 |
+
if doc_text:
|
| 148 |
+
token_count = len(tokenizer.encode(doc_text))
|
| 149 |
+
st.caption(f"Tokens: {token_count}/{MAX_CONTEXT_TOKENS}")
|
| 150 |
+
st.text(doc_text[:400] + " [...]" if len(doc_text) > 400 else doc_text)
|
| 151 |
+
|
| 152 |
+
# Rest of your workflow...
|
| 153 |
+
else:
|
| 154 |
+
st.info("Please upload a document to start.")
|
| 155 |
+
resource_dashboard(None, None)
|