Spaces:
Sleeping
Sleeping
Update app.py
Browse files202 unmodified lines2032042052062062082072082102092102114 unmodified lines21621721822122221922022422122222622722322423022522622722863 unmodified lines2922932943003013023033043053063073083093103112952962972982991 unmodified line30130230331930430530632232332430730830931031131231331456 unmodified lines371372373389374375376377202 unmodified lines actual_model_used = sel_model
try: # Collect all chunks and the final model used final_reply_chunks = [] last_model_used_during_stream = sel_model # Initialize to selected last_model_used_during_stream = sel_model # Generator for safe_chat_stream needs to be consumed fully stream_generator = safe_chat_stream(convo, ctx, rep, models_to_try) while True:4 unmodified lines if model_name_during_stream: last_model_used_during_stream = model_name_during_stream yield 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 chunks final_reply_chunks.append(part) # Store the last complete part or accumulated final_reply_chunks.append(part) except StopIteration: break # Generator exhausted break
# 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 object 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%)" ), # Adjusting specific colors for a harmonious look text_color_subdued="hsl(180, 50%, 70%)", # Lighter cyan for subdued text text_color_header="hsl(180, 100%, 70%)", # Vibrant cyan for headers border_color_accent="hsl(180, 100%, 50%)", # Cyan accent borders color_accent="hsl(180, 100%, 50%)", # Cyan accents shadow_color="hsla(180, 100%, 50%, 0.5)", # Cyan glow shadow background_fill_primary="hsl(240, 20%, 8%)", # Even darker for main background background_fill_secondary="hsl(240, 20%, 12%)", # Slightly lighter for secondary blocks # Ensure button text color is dark for contrast on bright buttons button_primary_text_color="hsl(240, 20%, 8%)", button_secondary_text_color="hsl(280, 100%, 70%)", # Magenta for secondary button text ) # Removed specific color overrides here as they are handled by external CSS.)
1 unmodified line title="🌳 JadeGPT", theme=jade_synthwave_theme, analytics_enabled=False, # Link external CSS and JS files # Link external CSS (font first, then custom style) css=""" @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. /* 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 effect gr.HTML(f""" <link rel="stylesheet" href="file=static/style.css"> <script src="file=static/script.js"></script>56 unmodified lines ex_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 feel with gr.Tab("System Calibration"): gr.Markdown("### Fine-Tune JadeGPT's Core Logic") with gr.Row(): mdl = gr.Dropdown(app.py+11-26