Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -707,4 +707,76 @@ with gr.Blocks(theme=themes.Soft(), css="""
|
|
| 707 |
label="Repetition Penalty",
|
| 708 |
value=1.2,
|
| 709 |
minimum=1.0,
|
| 710 |
-
maximum=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
label="Repetition Penalty",
|
| 708 |
value=1.2,
|
| 709 |
minimum=1.0,
|
| 710 |
+
maximum=2.0,
|
| 711 |
+
step=0.05,
|
| 712 |
+
info="Penalize repeated tokens"
|
| 713 |
+
)
|
| 714 |
+
max_new_tokens = gr.Slider(
|
| 715 |
+
label="Max New Tokens",
|
| 716 |
+
value=DEFAULT_MAX_NEW_TOKENS,
|
| 717 |
+
minimum=1,
|
| 718 |
+
maximum=MAX_MAX_NEW_TOKENS,
|
| 719 |
+
step=1,
|
| 720 |
+
info="Maximum length of generated response"
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
gr.Markdown(LICENSE)
|
| 724 |
+
gr.Markdown('<p class="performance-note">⚡ Performance optimized with caching and improved error handling</p>')
|
| 725 |
+
|
| 726 |
+
def update_growth_rate_label(growth_rate):
|
| 727 |
+
return f"**Selected Growth Rate: {growth_rate}%**"
|
| 728 |
+
|
| 729 |
+
def user(message, history):
|
| 730 |
+
if not message:
|
| 731 |
+
return "", history
|
| 732 |
+
return "", history + [{"role": "user", "content": message}]
|
| 733 |
+
|
| 734 |
+
def bot(history, sys_prompt, temp, tp, tk, rp, mnt, portfolio_df, growth_rate):
|
| 735 |
+
if not history:
|
| 736 |
+
logger.warning("History is empty, initializing with user message.")
|
| 737 |
+
history = [{"role": "user", "content": ""}]
|
| 738 |
+
|
| 739 |
+
message = history[-1]["content"]
|
| 740 |
+
portfolio_data, chart_alloc = process_portfolio(portfolio_df, growth_rate)
|
| 741 |
+
|
| 742 |
+
if portfolio_data:
|
| 743 |
+
message += "\n\n" + portfolio_data
|
| 744 |
+
|
| 745 |
+
history[-1]["content"] = message
|
| 746 |
+
history.append({"role": "assistant", "content": ""})
|
| 747 |
+
|
| 748 |
+
for new_text in generate(message, history[:-1], sys_prompt, mnt, temp, tp, tk, rp):
|
| 749 |
+
history[-1]["content"] = new_text
|
| 750 |
+
yield history, f"**Selected Growth Rate: {growth_rate}%**"
|
| 751 |
+
|
| 752 |
+
if chart_alloc:
|
| 753 |
+
# Append chart as a separate message
|
| 754 |
+
yield history, f"**Selected Growth Rate: {growth_rate}%**"
|
| 755 |
+
|
| 756 |
+
growth_rate.change(update_growth_rate_label, inputs=growth_rate, outputs=growth_rate_label)
|
| 757 |
+
|
| 758 |
+
submit.click(
|
| 759 |
+
user,
|
| 760 |
+
[msg, chatbot],
|
| 761 |
+
[msg, chatbot],
|
| 762 |
+
queue=False
|
| 763 |
+
).then(
|
| 764 |
+
bot,
|
| 765 |
+
[chatbot, system_prompt, temperature, top_p, top_k, repetition_penalty, max_new_tokens, portfolio_df, growth_rate],
|
| 766 |
+
[chatbot, growth_rate_label]
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
msg.submit(
|
| 770 |
+
user,
|
| 771 |
+
[msg, chatbot],
|
| 772 |
+
[msg, chatbot],
|
| 773 |
+
queue=False
|
| 774 |
+
).then(
|
| 775 |
+
bot,
|
| 776 |
+
[chatbot, system_prompt, temperature, top_p, top_k, repetition_penalty, max_new_tokens, portfolio_df, growth_rate],
|
| 777 |
+
[chatbot, growth_rate_label]
|
| 778 |
+
)
|
| 779 |
+
|
| 780 |
+
clear.click(lambda: [], None, chatbot, queue=False)
|
| 781 |
+
|
| 782 |
+
demo.queue(max_size=128).launch()
|