"""Main Streamlit app for ScicoQA Discrepancy Detection Demo.""" import logging import os import time from pathlib import Path import streamlit as st from dotenv import load_dotenv from core.arxiv2md_demo import Arxiv2MD from core.code_loader_demo import CodeLoader from core.llm_demo import LLM from core.model_config import ( PROVIDER_PRESETS, # create_local_model_config, # TODO: Re-enable when local models are fixed create_provider_model_config, get_api_key_env_name, get_provider_from_model, ) # from core.ollama_models import fetch_ollama_models # TODO: Re-enable when local models are fixed from core.openrouter_models import fetch_free_models, get_model_config from core.prompt_demo import Prompt from core.token_counter_demo import TokenCounter from parsing import parse_discrepancies # Load environment variables load_dotenv() # Configure logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", ) logger = logging.getLogger(__name__) # Constants CONTEXT_BUFFER_FACTOR = 0.9 MAX_CONTEXT_SIZE = 131072 # Default max context # Page configuration st.set_page_config( page_title="SciCoQA Paper- Code Discrepancy Detection", page_icon="π¬", layout="wide", initial_sidebar_state=400, ) def _redact_secrets(text: str, secrets: list[str | None]) -> str: """Best-effort redaction for secrets that may appear in exception strings/logs.""" redacted = text for secret in secrets: if secret and secret in redacted: redacted = redacted.replace(secret, "***REDACTED***") return redacted def _safe_model_config_for_session(model_config: dict | None) -> dict | None: """Store model config in session state WITHOUT sensitive fields like API keys.""" if not model_config: return model_config # Shallow-copy and drop known secret keys safe = dict(model_config) safe.pop("api_key", None) safe.pop("apiKey", None) return safe def _is_context_length_error(error_msg: str) -> bool: """ Check if an error message indicates a context length error. Args: error_msg: The error message string Returns: True if it's a context length error, False otherwise """ error_lower = error_msg.lower() return ( "maximum context length" in error_lower or "requested about" in error_lower or ("context length is" in error_lower and "you requested" in error_lower) or "context window" in error_lower ) def _build_prompt( paper_text: str, code_loader: CodeLoader | None, code_text: str | None, model_config: dict, token_counter: TokenCounter, code_reduction_factor: float = 1.0, ) -> tuple[str, str, int, bool]: """ Build prompt by counting tokens and truncating code until prompt + paper + code < CONTEXT_BUFFER_FACTOR * model context length. Args: paper_text: The paper text code_loader: CodeLoader instance (if using GitHub repo) code_text: Raw code text (if using uploaded file) model_config: Model configuration dictionary token_counter: TokenCounter instance code_reduction_factor: Factor to reduce code tokens (1.0 = no reduction, 0.9 = 10% reduction, etc.) Returns: Tuple of (final_prompt, code_prompt, final_tokens, code_was_truncated) """ max_context = model_config["max_context"] max_total_tokens = int(max_context * CONTEXT_BUFFER_FACTOR) # Build prompt template prompt_template = Prompt("discrepancy_generation") # Calculate tokens for template + paper template_with_paper = prompt_template(paper=paper_text, code="") tokens_template_and_paper = token_counter(template_with_paper) # Calculate remaining tokens for code (with reduction factor) remaining_code_tokens = int((max_total_tokens - tokens_template_and_paper) * code_reduction_factor) if remaining_code_tokens <= 0: raise ValueError( f"Paper text too long: {tokens_template_and_paper} tokens exceeds " f"{int(CONTEXT_BUFFER_FACTOR * 100)}% of context limit ({max_total_tokens} tokens)" ) logger.info( f"Template + paper tokens: {tokens_template_and_paper}, " f"Remaining for code (with {code_reduction_factor:.1%} factor): {remaining_code_tokens}" ) # Track original code size to detect truncation original_code_size = 0 if code_loader: # For CodeLoader, we can't easily get original size, so we'll check if code_prompt is empty/minimal original_code_size = -1 # Special value to indicate we can't determine elif code_text: original_code_size = len(code_text) # Get code prompt with token limit code_was_truncated = False if code_loader: # Use CodeLoader for GitHub repos code_prompt = code_loader.get_code_prompt( token_counter=token_counter, max_tokens=remaining_code_tokens, ) # Check if code was truncated by comparing token count code_tokens_used = token_counter(code_prompt) code_was_truncated = code_tokens_used >= remaining_code_tokens * 0.95 # If we used 95%+ of limit, likely truncated else: # Truncate code text to fit within token limit code_prompt = "" code_tokens = 0 if code_text and remaining_code_tokens > 0: code_lines = code_text.split('\n') for line in code_lines: line_with_newline = line + '\n' line_tokens = token_counter(line_with_newline) if code_tokens + line_tokens > remaining_code_tokens: logger.warning(f"Truncating code at {code_tokens} tokens (limit: {remaining_code_tokens})") code_was_truncated = True break code_prompt += line_with_newline code_tokens += line_tokens # Check if we truncated (code_prompt is shorter than original) if len(code_prompt) < original_code_size: code_was_truncated = True # Construct final prompt and verify it's within limit final_prompt = prompt_template(paper=paper_text, code=code_prompt) final_tokens = token_counter(final_prompt) if final_tokens > max_total_tokens: raise ValueError( f"Final prompt too long: {final_tokens} tokens exceeds " f"{int(CONTEXT_BUFFER_FACTOR * 100)}% of context limit ({max_total_tokens} tokens)" ) logger.info(f"Final prompt tokens: {final_tokens} (limit: {max_total_tokens})") return final_prompt, code_prompt, final_tokens, code_was_truncated def validate_urls(arxiv_url: str, github_url: str) -> tuple[bool, str]: """Validate input URLs.""" if not arxiv_url: return False, "Please provide an arXiv URL" if not github_url: return False, "Please provide a GitHub URL" if "arxiv.org" not in arxiv_url and not arxiv_url.startswith("http"): # Try to construct URL from ID if arxiv_url.replace(".", "").replace("v", "").isdigit(): arxiv_url = f"https://arxiv.org/abs/{arxiv_url}" else: return False, "Invalid arXiv URL format" if "github.com" not in github_url: return False, "Please provide a valid GitHub URL" return True, "" def validate_files(paper_file, code_file) -> tuple[bool, str]: """Validate uploaded files.""" if paper_file is None: return False, "Please upload a paper markdown file" if code_file is None: return False, "Please upload a repository text file" # Check file types if paper_file.name and not paper_file.name.endswith(('.md', '.markdown', '.txt')): return False, "Paper file should be a markdown (.md) or text (.txt) file" if code_file.name and not code_file.name.endswith('.txt'): return False, "Repository file should be a text (.txt) file" return True, "" def process_discrepancy_detection( paper_text: str | None = None, code_text: str | None = None, arxiv_url: str | None = None, github_url: str | None = None, model_config: dict | None = None, ): """Main processing pipeline for discrepancy detection.""" results = { "paper_text": None, "code_prompt": None, "prompt": None, "llm_response": None, "discrepancies": None, "error": None, "step_timings": None, } # Use a single compact status container step_timings = {} # Store timings for each step # Note: Uploaded files (paper_text, code_text) are only in memory and never saved # URL fetches (arxiv_url, github_url) use persistent cache directories for performance try: with st.status("π Processing...", expanded=False) as status: try: # Step 1: Fetch/process paper step_start = time.time() if arxiv_url: # Fetch from arXiv - use persistent cache directory status.update(label="π Fetching paper from arXiv...", state="running") try: # Use persistent directory for caching (OK to save fetched papers) arxiv2md = Arxiv2MD(output_dir=Path("data/papers")) paper_text = arxiv2md(arxiv_url) results["paper_text"] = paper_text step_time = time.time() - step_start step_timings["Paper Fetch"] = step_time st.write(f"β Paper fetched: {step_time:.1f}s") status.update( label=f"β Paper fetched ({step_time:.1f}s)", state="running", ) except Exception as e: error_msg = f"Error fetching paper: {str(e)}" logger.error(error_msg) results["error"] = error_msg status.update(label="β Error fetching paper", state="error") return results else: # Use provided paper text status.update(label="π Processing paper...", state="running") try: results["paper_text"] = paper_text step_time = time.time() - step_start step_timings["Paper Processing"] = step_time st.write(f"β Paper processed: {step_time:.1f}s") status.update( label=f"β Paper processed ({step_time:.1f}s)", state="running", ) except Exception as e: error_msg = f"Error processing paper: {str(e)}" logger.error(error_msg) results["error"] = error_msg status.update(label="β Error processing paper", state="error") return results # Step 2: Fetch/process code step_start = time.time() code_loader = None if github_url: # Fetch from GitHub - use persistent cache directory status.update(label="π¦ Fetching code from GitHub...", state="running") try: # Use persistent directory for caching (OK to save fetched repos) code_loader = CodeLoader( github_url=github_url, max_file_size_mb=1.0, raw_repo_dir=Path("data/repos-raw"), ) step_time = time.time() - step_start step_timings["Repository Clone"] = step_time st.write(f"β Repository cloned: {step_time:.1f}s") status.update( label=f"β Repository cloned ({step_time:.1f}s)", state="running", ) except Exception as e: error_msg = f"Error cloning repository: {str(e)}" logger.error(error_msg) results["error"] = error_msg status.update(label="β Error cloning repository", state="error") return results else: # Code text is already provided status.update(label="π¦ Processing repository...", state="running") step_time = time.time() - step_start step_timings["Code Processing"] = step_time st.write(f"β Repository processed: {step_time:.1f}s") status.update( label=f"β Repository processed ({step_time:.1f}s)", state="running", ) # Step 5: Calculate tokens and prepare prompt step_start = time.time() status.update(label="π Preparing prompt...", state="running") # Create token counter tokenizer_name = model_config["tokenizer"] token_counter = TokenCounter(model=tokenizer_name) try: # Build prompt with simple token counting final_prompt, code_prompt, final_tokens, code_was_truncated = _build_prompt( paper_text=paper_text, code_loader=code_loader, code_text=code_text, model_config=model_config, token_counter=token_counter, ) results["code_prompt"] = code_prompt results["prompt"] = final_prompt step_time = time.time() - step_start step_timings["Prompt Preparation"] = step_time st.write(f"β Prompt prepared: {step_time:.1f}s ({final_tokens:,} tokens)") status.update( label=f"β Prompt prepared ({step_time:.1f}s, {final_tokens:,} tokens)", state="running", ) except Exception as e: error_msg = f"Error preparing prompt: {str(e)}" logger.error(error_msg) results["error"] = error_msg status.update(label="β Error preparing prompt", state="error") return results # Step 6: Detect discrepancies with LLM (with retry on context length errors) step_start = time.time() status.update(label="π€\uFE0F Detecting discrepancies (this may take a while)...", state="running") # Retry configuration code_reduction_factor = 1.0 # Start with no reduction reduction_step = 0.1 # Reduce by 10% each time max_retries = 10 retry_count = 0 success = False current_final_prompt = final_prompt current_code_was_truncated = code_was_truncated while not success and retry_count < max_retries: try: # Rebuild prompt with reduced code if retrying if retry_count > 0: logger.info( f"Retrying with code reduction factor: {code_reduction_factor:.1%} " f"(attempt {retry_count}/{max_retries})" ) status.update( label=f"π Retrying with reduced code ({code_reduction_factor:.0%})...", state="running" ) st.write(f"π Retrying with reduced code ({code_reduction_factor:.0%})...") # Rebuild prompt with reduced code current_final_prompt, code_prompt, final_tokens, current_code_was_truncated = _build_prompt( paper_text=paper_text, code_loader=code_loader, code_text=code_text, model_config=model_config, token_counter=token_counter, code_reduction_factor=code_reduction_factor, ) results["code_prompt"] = code_prompt results["prompt"] = current_final_prompt # Extract model configuration model = model_config["model"] api_key = model_config.get("api_key") api_base = model_config.get("api_base") max_context = model_config.get("max_context") llm = LLM( model=model, api_key=api_key, api_base=api_base, temperature=1.0, top_p=1.0, reasoning_effort="high", max_context=max_context, ) response = llm(current_final_prompt) results["llm_response"] = response # Extract content from response choices = response.get("choices", []) if not choices: raise ValueError("No choices in LLM response") content = ( choices[0] .get("message", {}) .get("content", "") ) if not content: raise ValueError("Empty content in LLM response") # Parse discrepancies discrepancies = parse_discrepancies(content) results["discrepancies"] = discrepancies step_time = time.time() - step_start step_timings["LLM Inference"] = step_time total_time = sum(step_timings.values()) st.write(f"β LLM inference: {step_time:.1f}s") # Inform user if code was truncated if current_code_was_truncated: st.warning("β οΈ **Note**: Some code was truncated from the prompt due to context length limitations.") st.write("---") st.write(f"**Total time: {total_time:.1f}s**") if discrepancies: count = len(discrepancies) discrepancy_text = "discrepancy" if count == 1 else "discrepancies" status.update( label=f"β Complete! Found {count} {discrepancy_text} ({total_time:.1f}s total)", state="complete", ) else: status.update( label=f"β Complete! No discrepancies found ({total_time:.1f}s total)", state="complete", ) success = True except Exception as e: error_msg = str(e) api_key = model_config.get("api_key") if isinstance(model_config, dict) else None redacted_error = _redact_secrets(error_msg, [api_key]) # Check if it's a context length error if _is_context_length_error(error_msg): retry_count += 1 # Check if we can reduce code further # If code_reduction_factor is already at minimum (0.1), paper must be too long if code_reduction_factor <= 0.1: # Code is already minimal, paper must be too long error_msg = ( f"The paper text is too long for the model's context window. " f"Even with all code removed, the paper alone exceeds the context limit. " f"Please use a model with a larger context window or provide a shorter paper." ) logger.error(error_msg) results["error"] = error_msg status.update(label="β Paper too long for model", state="error") return results # Reduce code by 10% for next attempt code_reduction_factor = max(0.1, code_reduction_factor - reduction_step) logger.warning( f"Context length error detected: {redacted_error}. " f"Retrying with reduced code ({code_reduction_factor:.0%}) (attempt {retry_count}/{max_retries})" ) continue # Retry with reduced code else: # Not a context length error logger.error(f"Error during LLM inference: {redacted_error}") results["error"] = f"Error during LLM inference: {redacted_error}" status.update(label="β Error during inference", state="error") return results # If we exhausted retries if not success: error_msg = ( f"Could not fit prompt within context limits after {retry_count} retries. " f"The paper text may be too long for this model's context window." ) logger.error(error_msg) results["error"] = error_msg status.update(label="β Prompt too large for model", state="error") return results except Exception as e: api_key = model_config.get("api_key") if isinstance(model_config, dict) else None error_msg = f"Unexpected error: {_redact_secrets(str(e), [api_key])}" logger.error(error_msg, exc_info=True) results["error"] = error_msg status.update(label="β Unexpected error", state="error") return results results["step_timings"] = step_timings return results except Exception as e: # Handle any errors that occur outside the status context api_key = model_config.get("api_key") if isinstance(model_config, dict) else None error_msg = f"Unexpected error: {_redact_secrets(str(e), [api_key])}" logger.error(error_msg, exc_info=True) results["error"] = error_msg return results def main(): """Main Streamlit app.""" st.title("π¬ :rainbow[SciCoQA] Paper-Code Discrepancy Detection") st.markdown( """ _Detect discrepancies between scientific papers and their code implementations._ """ ) # About section in main area with st.expander("βΉοΈ About", expanded=False): st.markdown( """ This tool is a demo of our research paper on detecting discrepancies between scientific papers and their code implementations. You can read our paper here: [arXiv:2601.XXXX](https://arxiv.org/pdf/2601.XXXX). This tool helps researchers and developers identify inconsistencies between scientific papers and their corresponding code implementations. Such discrepancies can lead to reproducibility issues, incorrect implementations, or misunderstandings of the research. By using advanced LLMs to analyze both the paper text and code, this app automatically detects mismatches in algorithms, parameters, data processing steps, and other implementation details. **β οΈ Important Limitations:** Our research found that **recall is still low** - meaning the tool may miss some discrepancies. **All outputs should be used with human verification** and should not be relied upon as the sole method for discrepancy detection. **LLM Provider Recommendations:** - **Free Models (OpenRouter)**: Best for quick checks of already public paper+code combinations - **Provider Models (OpenAI, Anthropic, etc.)**: Best for high precision and best recall **Features:** - Support for multiple LLM providers (free or premium models) - Automatic content fetching from arXiv and GitHub - File upload support for custom papers and repositories - Secure API key handling (keys never stored or logged) **Resources:** - π¦ **Code**: [GitHub Repository](https://github.com/UKPLab/scicoqa) - π **Dataset**: [Hugging Face Dataset](https://huggingface.co/datasets/ukplab/scicoqa) - π **Project Website**: [ukplab.github.io/scicoqa](https://ukplab.github.io/scicoqa) **Citation:** If you find this tool useful, please cite our paper: ```bibtex @article{scicoqa2026, title = {SciCoQA: Quality Assurance for Scientific Paper-Code Alignment}, author = {BaumgΓ€rtner, Tim and Gurevych, Iryna}, journal = {arXiv preprint arXiv:XXXX.XXXXX}, year = {2026}, url = {https://github.com/UKPLab/scicoqa} } ``` """ ) # ========== SIDEBAR: Model Configuration ========== with st.sidebar: st.header("π€\uFE0F Model Configuration") # Determine label based on current selection model_config = None model_name = None display_model_name = None # Check if we have a model config in session state if "model_config" in st.session_state and st.session_state.model_config: existing_config = st.session_state.model_config display_model_name = existing_config.get("name") or existing_config.get("model", "Unknown") if display_model_name: st.caption(f"Current: {display_model_name}") # Model type selection model_type = st.radio( "Model Type", options=["Free Models (OpenRouter)", "Provider (OpenAI, Anthropic, Gemini, etc.)"], # options=["Free Models (OpenRouter)", "Local Model (Ollama/vLLM)", "Provider (OpenAI, Anthropic, Gemini, etc.)"], # TODO: Re-enable Local Model option when fixed help="Select free models (no API key) or provider models (requires API key)", # help="Select free models (no API key), local models (Ollama/vLLM), or provider models (requires API key)", # TODO: Re-enable when local models are fixed key="model_type_radio", index=0, # Default to Free Models ) # Store in session state for access outside sidebar st.session_state.model_type = model_type st.divider() # Model selection based on type if model_type == "Free Models (OpenRouter)": # Fetch free models from OpenRouter API (uses file-based cache, refreshes daily) if "free_models_cache" not in st.session_state: with st.spinner("Loading free models from OpenRouter..."): free_models_raw = fetch_free_models() st.session_state.free_models_cache = free_models_raw free_models_raw = st.session_state.free_models_cache if not free_models_raw: st.error("β οΈ Could not fetch free models from OpenRouter. Please try again later or use a different model type.") model_config = None else: # Show privacy warning st.warning( "β οΈ **Privacy Notice**: Free models are provided via [OpenRouter](https://openrouter.ai). " "The model provider may log your prompts and outputs. For enhanced privacy, consider using Provider models with your own API keys." ) # Create model options from fetched models model_options = {get_model_config(m)["name"]: get_model_config(m) for m in free_models_raw} if model_options: # Find default index for gpt-oss model_names = list(model_options.keys()) default_index = 0 for idx, name in enumerate(model_names): if "nemotron 3 nano 30b" in name.lower(): default_index = idx break model_name = st.selectbox( "Select Free Model", options=model_names, help="Free models via OpenRouter (no API key required)", key="free_model_select", index=default_index, ) model_config = model_options[model_name] else: st.error("β οΈ No free models available. Please try again later or use a different model type.") model_config = None # TODO: Re-enable when local models are fixed # elif model_type == "Local Model (Ollama/vLLM)": # st.info("π₯οΈ **Local Model**: Use models running locally via Ollama or vLLM (OpenAI-compatible server).") # # local_model_type = st.radio( # "Local Server Type", # options=["Ollama", "vLLM (OpenAI-compatible)"], # help="Select the type of local server", # key="local_server_type", # ) # # if local_model_type == "Ollama": # # API Base URL comes first # api_base = st.text_input( # "API Base URL", # value="http://localhost:11434", # help="Ollama API base URL", # key="ollama_api_base", # ) # # # Query Ollama for available models if API base is provided # model_input = None # if api_base and api_base.strip(): # try: # with st.spinner("Fetching available models from Ollama..."): # available_models = fetch_ollama_models(api_base.strip()) # # if available_models: # model_input = st.selectbox( # "Select Model", # options=available_models, # help="Select a model from your Ollama server", # key="ollama_model_select", # ) # else: # st.warning("β οΈ No models found or unable to connect to Ollama. You can still enter a model name manually.") # model_input = st.text_input( # "Model Name (manual entry)", # placeholder="e.g., llama2, mistral, codellama", # help="Enter the Ollama model name manually (without 'ollama/' prefix)", # key="ollama_model_input_manual", # ) # except Exception as e: # logger.error(f"Error fetching Ollama models: {e}") # st.warning(f"β οΈ Could not fetch models from Ollama: {str(e)}. You can still enter a model name manually.") # model_input = st.text_input( # "Model Name (manual entry)", # placeholder="e.g., llama2, mistral, codellama", # help="Enter the Ollama model name manually (without 'ollama/' prefix)", # key="ollama_model_input_manual", # ) # else: # st.info("π‘ Enter the API Base URL above to see available models, or enter a model name manually below.") # model_input = st.text_input( # "Model Name", # placeholder="e.g., llama2, mistral, codellama", # help="Enter the Ollama model name (without 'ollama/' prefix)", # key="ollama_model_input", # ) # # max_context = st.number_input( # "Max Context (tokens)", # min_value=1000, # max_value=1000000, # value=131072, # step=1000, # help="Maximum context window size in tokens", # key="ollama_max_context", # ) # # if model_input and api_base: # model_name = f"ollama/{model_input}" # model_config = create_local_model_config( # model=model_name, # api_base=api_base.strip(), # max_context=max_context, # ) # else: # vLLM # model_input = st.text_input( # "Model Name", # placeholder="e.g., gpt-3.5-turbo, mistralai/Mistral-7B-Instruct-v0.1", # help="Enter the model name for vLLM", # key="vllm_model_input", # ) # api_base = st.text_input( # "API Base URL", # value="http://localhost:8000/v1", # help="vLLM API base URL (OpenAI-compatible endpoint)", # key="vllm_api_base", # ) # max_context = st.number_input( # "Max Context (tokens)", # min_value=1000, # max_value=1000000, # value=131072, # step=1000, # help="Maximum context window size in tokens", # key="vllm_max_context", # ) # # if model_input: # model_name = model_input # model_config = create_local_model_config( # model=model_name, # api_base=api_base, # max_context=max_context, # ) else: # Provider Model st.info("π **Provider Model**: Use your own API keys to access premium models. Your keys are never stored, logged, or displayed.") provider_subtype = st.radio( "Model Selection", options=["Preset", "Custom"], help="Select from preset models or enter a custom model", key="provider_subtype", ) if provider_subtype == "Preset": model_name = st.selectbox( "Select Model", options=list(PROVIDER_PRESETS.keys()), help="Select a preset model (API key required)", key="preset_model_select", ) preset_config = PROVIDER_PRESETS[model_name] api_key_env = preset_config["api_key_env"] api_key_label = api_key_env.replace("_", " ").title() api_key = st.text_input( f"{api_key_label}", type="password", help=f"Enter your {api_key_label}. Your key is never stored, logged, or displayed.", placeholder=f"sk-..." if "OPENAI" in api_key_env else "Enter API key", key="preset_api_key", ) if api_key: model_config = create_provider_model_config( model=preset_config["model"], api_key=api_key, max_context=preset_config["max_context"], tokenizer=preset_config["tokenizer"], ) else: # Custom custom_model_name = st.text_input( "Model Name (litellm format)", placeholder="e.g., openai/gpt-5.2, anthropic/claude-sonnet-4-5, gemini/gemini-3-pro-preview", help="Enter the model name in litellm format. See [litellm documentation](https://docs.litellm.ai/docs/providers) for supported formats.", key="custom_model_name", ) custom_max_context = st.number_input( "Max Context (tokens)", min_value=1000, max_value=10000000, value=128000, step=1000, help="Maximum context window size in tokens", key="custom_max_context", ) if custom_model_name: provider = get_provider_from_model(custom_model_name) api_key_env = get_api_key_env_name(provider) api_key_label = api_key_env.replace("_", " ").title() api_key = st.text_input( f"{api_key_label}", type="password", help=f"Enter your {api_key_label}. Your key is never stored, logged, or displayed.", placeholder=f"sk-..." if "OPENAI" in api_key_env else "Enter API key", key="custom_api_key", ) if api_key: model_name = custom_model_name model_config = create_provider_model_config( model=custom_model_name, api_key=api_key, max_context=custom_max_context, ) st.markdown( "π **Need help with model format?** See the [litellm documentation](https://docs.litellm.ai/docs/providers) " "for supported providers and model naming conventions." ) st.caption("π Your API key is secure: never stored, logged, or displayed") # Show model info if model is selected if model_config: display_name = model_config.get("name") or model_config.get("model", model_name or "Unknown") st.caption(f"π Max Context: {model_config['max_context']:,} tokens") # ========== MAIN AREA: Input Form and Results ========== # Store model config in session state for next render if model_config: st.session_state.model_config = _safe_model_config_for_session(model_config) st.session_state.model_name = model_config.get("name") or model_config.get("model", model_name or "Unknown") # Input form with st.form("discrepancy_form"): # Input method selection using tabs tab_links, tab_files = st.tabs(["arXiv and GitHub Links", "Upload Paper and Code Files"]) # Initialize variables arxiv_url = None github_url = None paper_file = None code_file = None input_method = None with tab_links: col1, col2 = st.columns(2) with col1: arxiv_url = st.text_input( "arXiv Paper", value=st.session_state.get("example_arxiv_url", ""), placeholder="https://arxiv.org/abs/2006.12834 or 2006.12834", help="Enter the arXiv paper URL or just the paper ID", label_visibility="visible", ) with col2: github_url = st.text_input( "GitHub Code", value=st.session_state.get("example_github_url", ""), placeholder="https://github.com/username/repo", help="Enter the full GitHub repository URL", label_visibility="visible", ) if arxiv_url or github_url: input_method = "arXiv and GitHub Links" with tab_files: # Instructions section for file preparation with st.expander("π How to prepare files", expanded=False): st.markdown("""