File size: 2,137 Bytes
ad9b99b
 
 
 
de23a48
 
 
ad9b99b
 
 
de23a48
 
 
ad9b99b
 
 
 
 
 
 
 
 
de23a48
 
 
 
 
 
 
 
 
 
ad9b99b
 
 
 
81b9a71
 
ad9b99b
81b9a71
ad9b99b
81b9a71
 
ad9b99b
 
 
 
81b9a71
 
 
 
 
 
 
ad9b99b
 
de23a48
ad9b99b
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import pypokedex
import json
import utils
import datetime
from huggingface_hub import login, HfApi
import os

streaks = utils.get_streak()
pokemons = utils.get_pokemon()
hf_token = os.environ["HF_TOKEN"]
login(hf_token)
hfapi = HfApi()

def new_streak(intensity):
    global pokemons
    pokemons = utils.get_pokemon()

    reward = utils.new_streak(intensity)
    new_streak = utils.get_streak()
    return f"{new_streak} streak days", '## ' + 'βœ…  ' * new_streak, reward

def restart():
    with open('dummy.txt', 'w') as f:
        f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    hfapi.upload_file(
            path_or_fileobj="dummy.txt",
            path_in_repo="dummy.txt",
            repo_id="panda1835/pokemon-habit",
            repo_type="space",
        )

with gr.Blocks() as demo:

    gr.Markdown('<h1 style="text-align: center;">PokeVerse</h1>')
    reward_md = gr.Markdown()
    winning_btn = gr.Button("πŸ’ͺ Are you winning today? πŸ’ͺ")
    restart_btn = gr.Button("πŸ€ Restart πŸ€")
    intensity = gr.Slider(0, 3, step=1, label="Intensity")
    streak_md = gr.Markdown(f"### πŸ”₯ {streaks} streak days")
    streakboard = gr.Markdown('## ' + 'βœ…  ' * streaks)
    money_md = gr.Markdown(f"### πŸ’° Money saved: {'{:,}'.format(utils.get_money())} VND")
    money_md = gr.Markdown(f"### 🧱 Minifigure: {utils.get_total_minifigure()}")
    gr.Markdown('<h2 style="text-align: center;">My Poke Friends</h2>')

    with gr.Row():
        for dex in pokemons.keys():
            if pokemons[dex]['visible'] == True:
                with gr.Group():
                    with gr.Column(min_width=200) as poke_col:
                        gr.Image(pokemons[dex]['image'], show_label=False)
                        with gr.Accordion(pokemons[dex]['name'], open=False):
                            gr.Markdown(pokemons[dex]['description'])
                        info = gr.Markdown(f"**EXP**: {utils.get_poke_energy(dex)}")

    winning_btn.click(new_streak, inputs=[intensity], outputs=[streak_md, streakboard, reward_md])
    restart_btn.click(restart, None, None)
demo.launch()