Spaces:
Sleeping
Sleeping
Update app.py
Browse files202 unmodified lines2032042052062072082092102112122134 unmodified lines21821922022122222322422522622722822923023123223363 unmodified lines2972982993003013023033043053063073083093103113123133141 unmodified line31631731831932032132232332432532632732832956 unmodified lines386387388389390391392202 unmodified linesactual_model_used = sel_modeltry:# Collect all chunks and the final model usedfinal_reply_chunks = []last_model_used_during_stream = sel_model # Initialize to selected# Generator for safe_chat_stream needs to be consumed fullystream_generator = safe_chat_stream(convo, ctx, rep, models_to_try)while True:4 unmodified linesif model_name_during_stream:last_model_used_during_stream = model_name_during_streamyield hist, "", f"Generating with model: **{last_model_used_during_stream}**...", gr.File(value=None)# Keep collecting the reply parts if safe_chat_stream sends them in chunksfinal_reply_chunks.append(part) # Store the last complete part or accumulatedexcept StopIteration:break # Generator exhausted# After the loop, acc contains the full reply, last_model_used_during_stream is the actual model used.# Now, re-calculate usage for the final output.prompt_tokens_final = count_tokens(" ".join([msg["content"] for msg in trim_conversation(convo, last_model_used_during_stream, MODEL_DETAILS.get(last_model_used_during_stream, {}).get("max_context", ctx))]), last_model_used_during_stream)completion_tokens_final = count_tokens(acc, last_model_used_during_stream)usage_final = type('obj', (object,), {'prompt_tokens': prompt_tokens_final, 'completion_tokens': completion_tokens_final})() # Create a dummy usage objectif usage_final:pt, ct = usage_final.prompt_tokens, usage_final.completion_tokens63 unmodified lines"hsl(240, 20%, 50%)","hsl(240, 20%, 55%)","hsl(240, 20%, 60%)"),# Adjusting specific colors for a harmonious looktext_color_subdued="hsl(180, 50%, 70%)", # Lighter cyan for subdued texttext_color_header="hsl(180, 100%, 70%)", # Vibrant cyan for headersborder_color_accent="hsl(180, 100%, 50%)", # Cyan accent borderscolor_accent="hsl(180, 100%, 50%)", # Cyan accentsshadow_color="hsla(180, 100%, 50%, 0.5)", # Cyan glow shadowbackground_fill_primary="hsl(240, 20%, 8%)", # Even darker for main backgroundbackground_fill_secondary="hsl(240, 20%, 12%)", # Slightly lighter for secondary blocks# Ensure button text color is dark for contrast on bright buttonsbutton_primary_text_color="hsl(240, 20%, 8%)",button_secondary_text_color="hsl(280, 100%, 70%)", # Magenta for secondary button text)1 unmodified linetitle="🌳 JadeGPT",theme=jade_synthwave_theme,analytics_enabled=False,# Link external CSS and JS filescss="""@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');""",# This directly embeds CSS, but for larger styles, linking external files is better.# We'll use the `gr.HTML` for comprehensive CSS/JS injection below.) as demo:# Use gr.HTML to load external CSS and JSgr.HTML(f"""<link rel="stylesheet" href="file=static/style.css"><script src="file=static/script.js"></script>56 unmodified linesex_drop = gr.Dropdown(ex_list, label="Engage Protocol (Examples)", info="Select a pre-programmed query to begin.")ex_btn = gr.Button("Load Protocol", scale=0)with gr.Tab("System Calibration"): # Renamed for synthwave feelgr.Markdown("### Fine-Tune JadeGPT's Core Logic")with gr.Row():mdl = gr.Dropdown(202 unmodified lines2032042052062072082092102114 unmodified lines21621721821922022122222322422522622722863 unmodified lines2922932942952962972982991 unmodified line30130230330430530630730830931031131231331456 unmodified lines371372373374375376377202 unmodified linesactual_model_used = sel_modeltry:final_reply_chunks = []last_model_used_during_stream = sel_modelstream_generator = safe_chat_stream(convo, ctx, rep, models_to_try)while True:4 unmodified linesif model_name_during_stream:last_model_used_during_stream = model_name_during_streamyield hist, "", f"Generating with model: **{last_model_used_during_stream}**...", gr.File(value=None)final_reply_chunks.append(part)except StopIteration:breakprompt_tokens_final = count_tokens(" ".join([msg["content"] for msg in trim_conversation(convo, last_model_used_during_stream, MODEL_DETAILS.get(last_model_used_during_stream, {}).get("max_context", ctx))]), last_model_used_during_stream)completion_tokens_final = count_tokens(acc, last_model_used_during_stream)usage_final = type('obj', (object,), {'prompt_tokens': prompt_tokens_final, 'completion_tokens': completion_tokens_final})()if usage_final:pt, ct = usage_final.prompt_tokens, usage_final.completion_tokens63 unmodified lines"hsl(240, 20%, 50%)","hsl(240, 20%, 55%)","hsl(240, 20%, 60%)")# Removed specific color overrides here as they are handled by external CSS.)1 unmodified linetitle="🌳 JadeGPT",theme=jade_synthwave_theme,analytics_enabled=False,# Link external CSS (font first, then custom style)css="""@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');/* Gradio will load this first, then our custom style.css will override/add */""") as demo:# Use gr.HTML to load external CSS and JS# This div contains the main title and slogan with inline styles for the glow effectgr.HTML(f"""<link rel="stylesheet" href="file=static/style.css"><script src="file=static/script.js"></script>56 unmodified linesex_drop = gr.Dropdown(ex_list, label="Engage Protocol (Examples)", info="Select a pre-programmed query to begin.")ex_btn = gr.Button("Load Protocol", scale=0)with gr.Tab("System Calibration"):gr.Markdown("### Fine-Tune JadeGPT's Core Logic")with gr.Row():mdl = gr.Dropdown(
app.py+11-26