@@ -592,14 +592,6 @@ def render_document_upload(chat_manager):
592
592
st .header ("Upload Document" )
593
593
st .info ("Upload a PDF document to start chatting" )
594
594
595
- # Clear upload button for problematic files
596
- col1 , col2 = st .columns ([3 , 1 ])
597
- with col2 :
598
- if st .button ("🗑️ Clear Upload" , help = "Clear file upload state if stuck" ):
599
- # Force clear the uploader by creating a new chat
600
- chat_manager .create_new_chat (clear_rag = True ) # Clear RAG when clearing upload issues
601
- st .rerun ()
602
-
603
595
# Use a unique key per chat to avoid file state conflicts
604
596
uploader_key = f"uploader_{ st .session_state .current_chat_id } "
605
597
uploaded_file = st .file_uploader (
@@ -693,39 +685,22 @@ def render_document_upload(chat_manager):
693
685
)
694
686
695
687
if error :
696
- st .warning (f"Could not check context compatibility: { error } " )
688
+ st .markdown ("---" )
689
+ st .info (f"ℹ️ { error } " )
690
+ st .caption ("Context checking requires model configuration that includes context window size." )
697
691
elif context_info :
698
692
usage_percent = context_info ['usage_percent' ]
699
693
700
- # Always show progress bar and basic info after upload
701
- st .markdown ("---" )
702
- st .markdown ("**📊 Context Check:**" )
703
-
704
- # Show progress bar for context usage
705
- progress_value = min (usage_percent / 100 , 1.0 ) # Cap at 100% for display
706
- st .progress (progress_value , text = f"Context Usage: { usage_percent :.1f} %" )
707
-
708
- # Show status with appropriate color and clear messaging
694
+ # Only show warnings for serious issues (>80% usage)
709
695
if usage_percent > 100 :
696
+ st .markdown ("---" )
710
697
st .error (f"⚠️ **Document too large** - Uses { usage_percent :.0f} % of context window" )
711
698
excess_tokens = context_info ['total_estimated_tokens' ] - context_info ['context_length' ]
712
699
st .caption (f"Document exceeds limit by ~{ excess_tokens :,} tokens" )
713
700
elif usage_percent > 80 :
701
+ st .markdown ("---" )
714
702
st .warning (f"⚠️ **High context usage** - { usage_percent :.0f} % of { context_info ['context_length' ]:,} tokens" )
715
703
st .caption (f"~{ context_info ['available_tokens' ]:,} tokens remaining for conversation" )
716
- elif usage_percent > 50 :
717
- st .info (f"ℹ️ **Moderate context usage** - { usage_percent :.0f} % of { context_info ['context_length' ]:,} tokens" )
718
- st .caption (f"~{ context_info ['available_tokens' ]:,} tokens remaining for conversation" )
719
- else :
720
- st .success (f"✅ **Good fit** - Uses { usage_percent :.0f} % of { context_info ['context_length' ]:,} tokens" )
721
- st .caption (f"~{ context_info ['available_tokens' ]:,} tokens remaining for conversation" )
722
-
723
- # Show breakdown in expander
724
- with st .expander ("📊 Token Breakdown" , expanded = False ):
725
- st .write (f"**System prompt:** ~{ context_info ['system_tokens' ]:,} tokens" )
726
- st .write (f"**Response reserve:** ~{ context_info ['response_reserve' ]:,} tokens" )
727
- st .write (f"**Total estimated:** ~{ context_info ['total_estimated_tokens' ]:,} tokens" )
728
- st .write (f"**Context limit:** { context_info ['context_length' ]:,} tokens" )
729
704
else :
730
705
st .info ("💡 Select a model to check context window compatibility" )
731
706
@@ -791,19 +766,23 @@ def render_chat_interface(chat_manager):
791
766
chat ["document_text" ], st .session_state .selected_model
792
767
)
793
768
794
- if context_info :
769
+ if error :
770
+ st .markdown ("---" )
771
+ st .info (f"ℹ️ { error } " )
772
+ st .caption ("Context checking requires model configuration that includes context window size." )
773
+ elif context_info :
795
774
usage_percent = context_info ['usage_percent' ]
796
775
797
- # Show progress bar for context usage
798
- progress_value = min ( usage_percent / 100 , 1.0 ) # Cap at 100% for display
799
- st . progress ( progress_value , text = f"Context Usage: { usage_percent :.1f } % " )
800
-
801
- # Show brief summary
802
- st .caption (f"~ { context_info [ 'system_tokens' ]:, } tokens / { context_info [ 'context_length' ] :,} limit " )
803
-
804
- # Recommend RAG for large documents
805
- if usage_percent > 80 :
806
- st .info ( "💡 Consider enabling RAG for better handling of this large document " )
776
+ # Only show warnings for serious issues (>80% usage)
777
+ if usage_percent > 100 :
778
+ st . markdown ( "--- " )
779
+ st . error ( f"⚠️ **Document too large** - Uses { usage_percent :.0f } % of context window" )
780
+ excess_tokens = context_info [ 'total_estimated_tokens' ] - context_info [ 'context_length' ]
781
+ st .caption (f"Document exceeds limit by ~ { excess_tokens :,} tokens " )
782
+ elif usage_percent > 80 :
783
+ st . markdown ( "---" )
784
+ st . warning ( f"⚠️ **High context usage** - { usage_percent :.0f } % of { context_info [ 'context_length' ]:, } tokens" )
785
+ st .caption ( f"~ { context_info [ 'available_tokens' ]:, } tokens remaining for conversation " )
807
786
808
787
# Show PDF and extracted text side by side
809
788
if chat .get ("document_content" ) and chat .get ("document_text" ):
@@ -1278,11 +1257,7 @@ def main():
1278
1257
document_text , st .session_state .selected_model
1279
1258
)
1280
1259
1281
- if error :
1282
- st .markdown ("---" )
1283
- st .info (f"ℹ️ { error } " )
1284
- st .caption ("Context checking requires model configuration that includes context window size." )
1285
- elif context_info :
1260
+ if context_info :
1286
1261
usage_percent = context_info ['usage_percent' ]
1287
1262
1288
1263
# Only show warnings for serious issues (>80% usage)
0 commit comments