kouki321 commited on
Commit
0d98809
Β·
verified Β·
1 Parent(s): 44e22b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -124,7 +124,15 @@ def load_document_and_cache(file_path):
124
  return None, None, None
125
 
126
  # ==============================
127
- # Updated Main Workflow with Unique Temp Files
 
 
 
 
 
 
 
 
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 in preview
138
  with st.expander("πŸ“„ Document Preview"):
139
- token_count = len(tokenizer.encode(doc_text))
140
- st.caption(f"Tokens: {token_count}/{MAX_CONTEXT_TOKENS}")
141
- st.text(doc_text[:400] + " [...]" if len(doc_text) > 400 else doc_text)
142
-
143
- # ... (rest of the code remains similar but uses updated functions)
 
 
 
 
 
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)