Spaces:
Runtime error
Runtime error
import gradio as gr | |
from utils import get_calculated_df, get_info, text2oddslist | |
def calculate(amount, text): | |
df = get_calculated_df(amount, text2oddslist(text)) | |
info = get_info(df) | |
# dfの整形 | |
display_cols = ["odds", "buy", "refound"] | |
if df["name"].map(lambda name: name != "").any(): | |
display_cols = ["name"] + display_cols | |
# markdownの整形 | |
md_string = ( | |
f"**購入額:** ¥ **{info['sum']:,}**<br>" | |
f"**点数:** **{info['num_kind']}** 点<br>" | |
f"**払戻:** ¥ **{info['refound_mean']:,}** (**{info['profit_mean']:+,}** (**{info['rate_min']:+.0%}**))<br>" | |
"---" | |
) | |
return md_string, df[["index"] + display_cols] | |
amount_input = gr.Number(value=3000, label="amount") | |
text_input = gr.Textbox(label="text") | |
markdown_output = gr.Markdown() | |
df_output = gr.Dataframe(type="pandas") | |
iface = gr.Interface( | |
fn=calculate, | |
inputs=[amount_input, text_input], | |
outputs=[markdown_output, df_output], | |
) | |
iface.launch() | |