Spaces:
Runtime error
Runtime error
Update app.py
Browse files203 unmodified lines20420520620720820921018 unmodified lines22923023123223323423535 unmodified lines27127227327427527627789 unmodified lines36736836936737037137237346 unmodified lines4204214224204234244254263 unmodified lines43043143243043343443543643743843943744044144244351 unmodified lines4954964974954964984995005015025035045055065075085095105115125135143 unmodified lines51851952051452152252352441 unmodified lines56656756856956257057157257343 unmodified lines617618619612620203 unmodified lines# --------------------------------
# REINTRODUCING: perform_web_search functiondef perform_web_search(query): """MOCK WEB SEARCH: Only returns results for hard-coded queries.""" print(f"**Web Search Triggered for:** '{query}'")18 unmodified lines print("Skipping online update: Target response is corrupted or highly repetitive.") return
# RE-ADDED search prefix logic prefix_search = f"According to a search result: {to_ascii(search_context)}. " if search_context else "" prefix_file = f"Based on the attached file: {to_ascii(file_context)}. " if file_context else "" context_prefix = f"{conversation_context} " if conversation_context else ""35 unmodified lines
def generate_response(prompt, search_context="", conversation_context=""): """Generates a response using the GPT model with Top-K sampling.""" # RE-ADDED search prefix logic prefix_text = f"According to a search result: {to_ascii(search_context)}. " if search_context else "" context_prefix = f"{conversation_context} " if conversation_context else ""
89 unmodified lines clean_user_message, last_ai_response, max_length, search_context=search_context_text, search_context=search_context_text, file_context=file_context_text, conversation_context=conversation_context )46 unmodified lines # -----------------------------------------------------
search_context_text = "" # CRITICAL FIX 2: Only check for search need IF the web search is explicitly enabled (from the checkbox). # RE-ADDED: Check for search need IF the web search is explicitly enabled (from the checkbox). search_needed = bool(web_search_enabled) and ("?" in clean_user_message or any( clean_user_message.lower().startswith(q) for q in ["what is", "who is", "how to"] ))3 unmodified lines display_search_result = f"π **Search Result Used:** {search_context_text}" if search_context_text else "π **No Search Performed or Result Found.**" # If search was NOT enabled, overwrite the message to be definitively "No Search Performed." # RE-ADDED: If search was NOT enabled, overwrite the message to be definitively "No Search Performed." if not web_search_enabled: display_search_result = "π **Web Search Disabled by Menu.**"
final_model_prompt = f"{file_context} {model_prompt}" if file_context else model_prompt reply = generate_response( final_model_prompt, search_context=search_context_text, search_context=search_context_text, conversation_context=conversation_context )
51 unmodified lines# --- Gradio UI Definition ---
with gr.Blocks(title="OkemoLLM") as demo: gr.Markdown("# OkemoLLM (Online Learning & Web Search Enabled with 1-Turn Context) π") search_status_display = gr.Markdown("π Search status will appear here.") # RESTORED TITLE gr.Markdown("# OkemoLLM (Online Learning & Web Search Enabled with 1-Turn Context) π") # RESTORED STATUS search_status_display = gr.Markdown("π Search status will appear here.") chat = gr.Chatbot(height=500)
with gr.Row(): with gr.Column(scale=4): msg = gr.Textbox(placeholder="Type your messageβ¦", label="Message", elem_id="okemo-input-textbox") uploaded_file_state = gr.File(label="Uploaded File", visible=False, elem_id="uploaded_file_state") # RESTORED CHECKBOX web_search_enabled_state = gr.Checkbox(label="Enable Web Search", value=True)
clear = gr.Button("Clear") send_trigger = gr.Button(visible=False, elem_id="okemo-send-button-trigger")
3 unmodified lines updated_history = history + [[message, None]] return updated_history, "..."
# UI Chat Flow: Add message to history -> Then process and generate response # UI Chat Flow: All elements restored msg.submit( add_user_message_to_history, [msg, chat, uploaded_file_state, web_search_enabled_state],41 unmodified lines gr.Textbox(label="Message"), gr.State(value=[]), gr.File(label="Uploaded File"), # RESTORED CHECKBOX gr.Checkbox(label="Web Search Enabled"), gr.Checkbox(label="Web Search Enabled", value=True), ], outputs=[ gr.State(value=[]),43 unmodified lines
if __name__ == "__main__": # Using the demo.queue().launch() from app.py demo.queue(api_open=True).launch(ssr_mode=False) demo.queue(api_open=True).launch(ssr_mode=False)app.py+17-9