awacke1 commited on
Commit
5402d68
1 Parent(s): a51e81e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -37
app.py CHANGED
@@ -26,7 +26,7 @@ from huggingface_hub import InferenceClient
26
  from io import BytesIO
27
  from openai import ChatCompletion
28
  from PyPDF2 import PdfReader
29
- from templates import bot_template, css, user_template
30
  from xml.etree import ElementTree as ET
31
  import streamlit.components.v1 as components # Import Streamlit Components for HTML5
32
 
@@ -72,42 +72,6 @@ st.markdown("""
72
  """)
73
 
74
 
75
-
76
-
77
- # Ensure the directory for storing scores exists
78
- score_dir = "scores"
79
- os.makedirs(score_dir, exist_ok=True)
80
-
81
- # Function to generate a unique key for each button, including an emoji
82
- def generate_key(label, header, idx):
83
- return f"{header}_{label}_{idx}_key"
84
-
85
- # Function to increment and save score
86
- def update_score(key, increment=1):
87
- score_file = os.path.join(score_dir, f"{key}.json")
88
- if os.path.exists(score_file):
89
- with open(score_file, "r") as file:
90
- score_data = json.load(file)
91
- else:
92
- score_data = {"clicks": 0, "score": 0}
93
-
94
- score_data["clicks"] += 1
95
- score_data["score"] += increment
96
-
97
- with open(score_file, "w") as file:
98
- json.dump(score_data, file)
99
-
100
- return score_data["score"]
101
-
102
- # Function to load score
103
- def load_score(key):
104
- score_file = os.path.join(score_dir, f"{key}.json")
105
- if os.path.exists(score_file):
106
- with open(score_file, "r") as file:
107
- score_data = json.load(file)
108
- return score_data["score"]
109
- return 0
110
-
111
  roleplaying_glossary = {
112
  "🎴 Traditional Card Games": {
113
  "Bridge": ["Trick-taking", "Bidding and partnership", "Complex scoring"],
@@ -158,6 +122,43 @@ roleplaying_glossary = {
158
  }
159
 
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  def search_glossary(query):
162
  for category, terms in roleplaying_glossary.items():
163
  if query.lower() in (term.lower() for term in terms):
 
26
  from io import BytesIO
27
  from openai import ChatCompletion
28
  from PyPDF2 import PdfReader
29
+ #from templates import bot_template, css, user_template -- pattern with content
30
  from xml.etree import ElementTree as ET
31
  import streamlit.components.v1 as components # Import Streamlit Components for HTML5
32
 
 
72
  """)
73
 
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  roleplaying_glossary = {
76
  "🎴 Traditional Card Games": {
77
  "Bridge": ["Trick-taking", "Bidding and partnership", "Complex scoring"],
 
122
  }
123
 
124
 
125
+
126
+ # Ensure the directory for storing scores exists
127
+ score_dir = "scores"
128
+ os.makedirs(score_dir, exist_ok=True)
129
+
130
+ # Function to generate a unique key for each button, including an emoji
131
+ def generate_key(label, header, idx):
132
+ return f"{header}_{label}_{idx}_key"
133
+
134
+ # Function to increment and save score
135
+ def update_score(key, increment=1):
136
+ score_file = os.path.join(score_dir, f"{key}.json")
137
+ if os.path.exists(score_file):
138
+ with open(score_file, "r") as file:
139
+ score_data = json.load(file)
140
+ else:
141
+ score_data = {"clicks": 0, "score": 0}
142
+
143
+ score_data["clicks"] += 1
144
+ score_data["score"] += increment
145
+
146
+ with open(score_file, "w") as file:
147
+ json.dump(score_data, file)
148
+
149
+ return score_data["score"]
150
+
151
+ # Function to load score
152
+ def load_score(key):
153
+ score_file = os.path.join(score_dir, f"{key}.json")
154
+ if os.path.exists(score_file):
155
+ with open(score_file, "r") as file:
156
+ score_data = json.load(file)
157
+ return score_data["score"]
158
+ return 0
159
+
160
+
161
+
162
  def search_glossary(query):
163
  for category, terms in roleplaying_glossary.items():
164
  if query.lower() in (term.lower() for term in terms):