awacke1 commited on
Commit
ba78d32
1 Parent(s): 3cabe98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -47
app.py CHANGED
@@ -5,40 +5,18 @@ from components import GamePlay, Player, Dealer, Deck
5
  # PersistDataset -----
6
  import os
7
  import csv
8
- import gradio as gr
9
- from gradio import inputs, outputs
10
  import huggingface_hub
11
  from huggingface_hub import Repository, hf_hub_download, upload_file
12
  from datetime import datetime
 
13
  DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/Carddata.csv"
14
  DATASET_REPO_ID = "awacke1/Carddata.csv"
15
  DATA_FILENAME = "Carddata.csv"
16
  DATA_FILE = os.path.join("data", DATA_FILENAME)
17
  HF_TOKEN = os.environ.get("HF_TOKEN")
18
  # overriding/appending to the gradio template
19
- SCRIPT = """
20
- <script>
21
- if (!window.hasBeenRun) {
22
- window.hasBeenRun = true;
23
- console.log("should only happen once");
24
- document.querySelector("button.submit").click();
25
- }
26
- </script>
27
- """
28
- #with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
29
- # f.write(SCRIPT)
30
- try:
31
- hf_hub_download(
32
- repo_id=DATASET_REPO_ID,
33
- filename=DATA_FILENAME,
34
- cache_dir=DATA_DIRNAME,
35
- force_filename=DATA_FILENAME
36
- )
37
- except:
38
- print("file not found")
39
- repo = Repository(
40
- local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
41
- )
42
  def generate_html() -> str:
43
  with open(DATA_FILE) as csvfile:
44
  reader = csv.DictReader(csvfile)
@@ -57,6 +35,7 @@ def generate_html() -> str:
57
  html += "</div>"
58
  html += "</div>"
59
  return html
 
60
  def store_message(name: str, message: str):
61
  if name and message:
62
  with open(DATA_FILE, "a") as csvfile:
@@ -66,28 +45,11 @@ def store_message(name: str, message: str):
66
  )
67
  commit_url = repo.push_to_hub()
68
  return generate_html()
69
- iface = gr.Interface(
70
- store_message,
71
- [
72
- inputs.Textbox(placeholder="Your name"),
73
- inputs.Textbox(placeholder="Your message", lines=2),
74
- ],
75
- "html",
76
- css="""
77
- .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
78
- """,
79
- title="Reading/writing to a HuggingFace dataset repo from Spaces",
80
- description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
81
- article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
82
- )
83
- #iface.launch()
84
- # -------
85
-
86
  # Game settings
87
  number_of_decks = 6
88
  blackjack_multiplier = 1.5
89
 
90
-
91
  # Initialize player, dealer, deck and game play. Cache these variables
92
  @st.cache(allow_output_mutation=True, suppress_st_warning=True)
93
  def start_game():
@@ -97,7 +59,6 @@ def start_game():
97
  game_play = GamePlay(player, dealer, game_deck, blackjack_multiplier)
98
  return game_deck, dealer, player, game_play
99
 
100
-
101
  game_deck, dealer, player, game_play = start_game()
102
 
103
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
@@ -105,7 +66,6 @@ st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
105
  if st.button('New hand?'):
106
  game_play.deal_in()
107
 
108
-
109
  player_stats = st.empty()
110
  player_images = st.empty()
111
  player_hit_option = st.empty()
@@ -143,6 +103,4 @@ dealer_stats.write(dealer)
143
  dealer_images.image([Image.open(card.image_location)
144
  for card in dealer.cards], width=100)
145
 
146
- #r=store_message("Aaron Wacker", game_play)
147
-
148
  result.write(game_play)
 
5
  # PersistDataset -----
6
  import os
7
  import csv
8
+
 
9
  import huggingface_hub
10
  from huggingface_hub import Repository, hf_hub_download, upload_file
11
  from datetime import datetime
12
+
13
  DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/Carddata.csv"
14
  DATASET_REPO_ID = "awacke1/Carddata.csv"
15
  DATA_FILENAME = "Carddata.csv"
16
  DATA_FILE = os.path.join("data", DATA_FILENAME)
17
  HF_TOKEN = os.environ.get("HF_TOKEN")
18
  # overriding/appending to the gradio template
19
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def generate_html() -> str:
21
  with open(DATA_FILE) as csvfile:
22
  reader = csv.DictReader(csvfile)
 
35
  html += "</div>"
36
  html += "</div>"
37
  return html
38
+
39
  def store_message(name: str, message: str):
40
  if name and message:
41
  with open(DATA_FILE, "a") as csvfile:
 
45
  )
46
  commit_url = repo.push_to_hub()
47
  return generate_html()
48
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  # Game settings
50
  number_of_decks = 6
51
  blackjack_multiplier = 1.5
52
 
 
53
  # Initialize player, dealer, deck and game play. Cache these variables
54
  @st.cache(allow_output_mutation=True, suppress_st_warning=True)
55
  def start_game():
 
59
  game_play = GamePlay(player, dealer, game_deck, blackjack_multiplier)
60
  return game_deck, dealer, player, game_play
61
 
 
62
  game_deck, dealer, player, game_play = start_game()
63
 
64
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
 
66
  if st.button('New hand?'):
67
  game_play.deal_in()
68
 
 
69
  player_stats = st.empty()
70
  player_images = st.empty()
71
  player_hit_option = st.empty()
 
103
  dealer_images.image([Image.open(card.image_location)
104
  for card in dealer.cards], width=100)
105
 
 
 
106
  result.write(game_play)