Spaces:
Runtime error
Runtime error
File size: 1,030 Bytes
1058ca8 ea78fab 1058ca8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from utils import get_calculated_df, get_info, text2oddslist
def calculate(amount, text):
odds_list = text2oddslist(text)
df = get_calculated_df(amount, odds_list)
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()
|