kateforsberg commited on
Commit
c56aab6
·
1 Parent(s): 7a8cde9

updated .env

Browse files
app.py CHANGED
@@ -64,7 +64,7 @@ def generate_questions(
64
  return (
65
  "## Questions Ready for Download Below",
66
  gr.update(
67
- visible=True, value=f"{Path.cwd().joinpath('outputs/professor_guide.xlsx')}"
68
  ),
69
  gr.update(
70
  interactive=False
@@ -131,4 +131,4 @@ with gr.Blocks() as demo:
131
  # with gr.Blocks() as failed:
132
  # gr.Markdown("Environment Error - No username and password provided")
133
  # failed.launch()
134
- demo.launch()
 
64
  return (
65
  "## Questions Ready for Download Below",
66
  gr.update(
67
+ visible=True, value=f"{Path.cwd().joinpath('outputs/professor_guide.csv')}"
68
  ),
69
  gr.update(
70
  interactive=False
 
131
  # with gr.Blocks() as failed:
132
  # gr.Markdown("Environment Error - No username and password provided")
133
  # failed.launch()
134
+ demo.launch(auth=(os.environ.get('HF_USERNAME',''),os.environ.get('HF_PASSWORD','')))
uw_programmatic/base_machine.py CHANGED
@@ -14,6 +14,8 @@ from griptape.artifacts import ListArtifact, TextArtifact
14
  from griptape.configs import Defaults
15
  from griptape.configs.drivers import (
16
  OpenAiDriversConfig,
 
 
17
  )
18
  from griptape.drivers import (
19
  GriptapeCloudVectorStoreDriver,
@@ -56,6 +58,7 @@ Defaults.drivers_config = OpenAiDriversConfig(
56
  prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", max_tokens=4096)
57
  )
58
 
 
59
  def custom_dict_merge(dict1: dict, dict2: dict) -> dict:
60
  result = dict1.copy()
61
  for key, value in dict2.items():
 
14
  from griptape.configs import Defaults
15
  from griptape.configs.drivers import (
16
  OpenAiDriversConfig,
17
+ AnthropicDriversConfig,
18
+ GoogleDriversConfig,
19
  )
20
  from griptape.drivers import (
21
  GriptapeCloudVectorStoreDriver,
 
58
  prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", max_tokens=4096)
59
  )
60
 
61
+
62
  def custom_dict_merge(dict1: dict, dict2: dict) -> dict:
63
  result = dict1.copy()
64
  for key, value in dict2.items():
uw_programmatic/config.yaml CHANGED
@@ -34,7 +34,7 @@ rulesets:
34
  incorrect_answers_creator:
35
  name: Create Wrong Answers
36
  rules:
37
- - '"Return ONLY a list of 3 incorrect answers. No markdown, no commentary, no
38
  backticks.'
39
  - '"All incorrect answers should be different, but plausible answers to the question.'
40
  - '"Incorrect answers may reference material from the knowledge base, but must
 
34
  incorrect_answers_creator:
35
  name: Create Wrong Answers
36
  rules:
37
+ - '"Return ONLY a list of 4 incorrect answers. No markdown, no commentary, no
38
  backticks.'
39
  - '"All incorrect answers should be different, but plausible answers to the question.'
40
  - '"Incorrect answers may reference material from the knowledge base, but must
uw_programmatic/uw_machine.py CHANGED
@@ -1,15 +1,19 @@
1
  from __future__ import annotations
2
 
3
  import ast
 
4
  import csv
5
  import json
6
  from pathlib import Path
7
  import random
8
- from typing import TYPE_CHECKING
9
  from griptape.structures import Agent
 
10
  import pandas as pd
11
 
12
- from uw_programmatic.base_machine import UWBaseMachine
 
 
13
 
14
  if TYPE_CHECKING:
15
  from griptape.tools import BaseTool
@@ -26,6 +30,8 @@ class UWMachine(UWBaseMachine):
26
  """Starts the machine."""
27
  # Clear input history.
28
  # Clear csv file
 
 
29
  self.send("enter_first_state")
30
 
31
  def on_event_gather_parameters(self, event_: dict) -> None:
@@ -83,6 +89,21 @@ class UWMachine(UWBaseMachine):
83
  def on_enter_assess_generated_q(self) -> None:
84
  # TODO: Should it append it to the list already and remove duplicates? or not?
85
  # TODO: Merge incoming lists
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  merged_list = [*self.question_list, *self.most_recent_questions]
87
  prompt = f"{merged_list}"
88
  self.get_structure("similarity_auditor").run(prompt)
@@ -107,43 +128,60 @@ class UWMachine(UWBaseMachine):
107
  ) # This must be in that JSON format
108
  except:
109
  new_question_list = self.question_list
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  self.question_list = new_question_list
111
  self.send("next_state") # move on
112
 
113
  def on_enter_output_q(self) -> None:
114
- columns = pd.MultiIndex.from_tuples(
115
- [
116
- ("Professor", "Page Range"),
117
- ("Professor", "Taxonomy"),
118
- ("Professor", "Question"),
119
- ("Professor", "Answer"),
120
- ("Professor", "Wrong Answers"),
121
- ("Student", "Question"),
122
- ("Student", "Answers"),
123
- ]
124
- )
125
- data = pd.DataFrame(columns=columns)
126
- for question in range(len(self.question_list)):
127
- shuffled_answers = [
128
- self.question_list[question]["Answer"],
129
- *self.question_list[question]["Wrong Answers"],
130
- ]
131
- random.shuffle(shuffled_answers)
132
- shuffled_answers = "\n".join(shuffled_answers)
133
- new_row = [
134
- self.question_list[question]["Page"],
135
- self.question_list[question]["Taxonomy"],
136
- self.question_list[question]["Question"],
137
- self.question_list[question]["Answer"],
138
- self.question_list[question]["Wrong Answers"],
139
- self.question_list[question]["Question"],
140
- shuffled_answers,
141
- ]
142
- data.loc[question] = new_row
143
- data.columns = ["_".join(col).strip() for col in data.columns.values]
144
- writer = pd.ExcelWriter("outputs/professor_guide.xlsx", engine="xlsxwriter")
145
- data.to_excel(writer, sheet_name="Quiz Questions", index=False)
146
- writer.close()
147
  self.send("next_state")
148
 
149
  def on_event_output_q(self, event_: dict) -> None:
@@ -177,36 +215,21 @@ class UWMachine(UWBaseMachine):
177
  },
178
  ]
179
 
180
- columns = pd.MultiIndex.from_tuples(
181
- [
182
- ("Professor", "Page Range"),
183
- ("Professor", "Taxonomy"),
184
- ("Professor", "Question"),
185
- ("Professor", "Answer"),
186
- ("Professor", "Wrong Answers"),
187
- ("Student", "Question"),
188
- ("Student", "Answers"),
189
- ]
190
- )
191
- data = pd.DataFrame(columns=columns)
192
- for question in range(len(question_list)):
193
- shuffled_answers = [
194
- question_list[question]["Answer"],
195
- *question_list[question]["Wrong Answers"],
196
- ]
197
- random.shuffle(shuffled_answers)
198
- shuffled_answers = "\n".join(shuffled_answers)
199
- new_row = [
200
- question_list[question]["Page"],
201
- question_list[question]["Taxonomy"],
202
- question_list[question]["Question"],
203
- question_list[question]["Answer"],
204
- question_list[question]["Wrong Answers"],
205
- question_list[question]["Question"],
206
- shuffled_answers,
207
- ]
208
- data.loc[question] = new_row
209
- data.columns = ["_".join(col).strip() for col in data.columns.values]
210
- writer = pd.ExcelWriter("outputs/professor_guide.xlsx", engine="xlsxwriter")
211
- data.to_excel(writer, sheet_name="Quiz Questions", index=False)
212
- writer.close()
 
1
  from __future__ import annotations
2
 
3
  import ast
4
+ import xlsxwriter
5
  import csv
6
  import json
7
  from pathlib import Path
8
  import random
9
+ from typing import TYPE_CHECKING, Any
10
  from griptape.structures import Agent
11
+ from h11 import Event
12
  import pandas as pd
13
 
14
+ from base_machine import UWBaseMachine
15
+ from griptape.events import EventBus, EventListener, FinishStructureRunEvent, BaseEvent
16
+ from griptape.loaders import PdfLoader
17
 
18
  if TYPE_CHECKING:
19
  from griptape.tools import BaseTool
 
30
  """Starts the machine."""
31
  # Clear input history.
32
  # Clear csv file
33
+ with Path(Path.cwd().joinpath("outputs/similarity_step.csv")).open("w") as file:
34
+ file.write("")
35
  self.send("enter_first_state")
36
 
37
  def on_event_gather_parameters(self, event_: dict) -> None:
 
89
  def on_enter_assess_generated_q(self) -> None:
90
  # TODO: Should it append it to the list already and remove duplicates? or not?
91
  # TODO: Merge incoming lists
92
+ with Path(Path.cwd().joinpath("outputs/similarity_step.csv")).open(
93
+ "a", newline=""
94
+ ) as file:
95
+ writer = csv.DictWriter(
96
+ file,
97
+ fieldnames=[
98
+ "Question",
99
+ "Answer",
100
+ "Wrong Answers",
101
+ "Page",
102
+ "Taxonomy",
103
+ ],
104
+ )
105
+ writer.writerow({"Question": "LIST OF QUESTIONS GENERATED THIS ROUND"})
106
+ writer.writerows(self.most_recent_questions)
107
  merged_list = [*self.question_list, *self.most_recent_questions]
108
  prompt = f"{merged_list}"
109
  self.get_structure("similarity_auditor").run(prompt)
 
128
  ) # This must be in that JSON format
129
  except:
130
  new_question_list = self.question_list
131
+ merged_list = [
132
+ *self.question_list,
133
+ *self.most_recent_questions,
134
+ ]
135
+ deleted_q = [
136
+ question1
137
+ for question1 in merged_list
138
+ if not any(
139
+ question2["Question"] == question1["Question"]
140
+ for question2 in new_question_list
141
+ )
142
+ ]
143
+ with Path(
144
+ Path.cwd().joinpath("outputs/similarity_step.csv")
145
+ ).open("a", newline="") as file:
146
+ writer = csv.DictWriter(
147
+ file,
148
+ fieldnames=[
149
+ "Question",
150
+ "Answer",
151
+ "Wrong Answers",
152
+ "Page",
153
+ "Taxonomy",
154
+ ],
155
+ )
156
+ writer.writerow(
157
+ {"Question": "QUESTIONS REMOVED THIS ROUND!"}
158
+ )
159
+ if len(deleted_q):
160
+ writer.writerows(deleted_q)
161
+ else:
162
+ writer.writerow({"Question": "No q removed"})
163
  self.question_list = new_question_list
164
  self.send("next_state") # move on
165
 
166
  def on_enter_output_q(self) -> None:
167
+ with Path(Path.cwd().joinpath("outputs/professor_guide.csv")).open(
168
+ "w", newline=""
169
+ ) as file:
170
+ writer = csv.writer(file)
171
+ for question in range(len(self.question_list)):
172
+ # TODO: Shuffle answers according to row, keep correct answer in random section. Answer column is a number.
173
+ new_row = [self.question_list[question]["Question"]]
174
+ wrong_answers = list(self.question_list[question]["Wrong Answers"])
175
+ column = random.randint(1, len(wrong_answers) + 1)
176
+ new_row.append(column)
177
+ for i in range(1, len(wrong_answers) + 2):
178
+ if i == column:
179
+ new_row.append(self.question_list[question]["Answer"])
180
+ else:
181
+ new_row.append(wrong_answers.pop())
182
+ new_row.append(self.question_list[question]["Page"])
183
+ new_row.append(self.question_list[question]["Taxonomy"])
184
+ writer.writerow(new_row)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  self.send("next_state")
186
 
187
  def on_event_output_q(self, event_: dict) -> None:
 
215
  },
216
  ]
217
 
218
+ with Path(Path.cwd().joinpath("outputs/professor_guide.csv")).open(
219
+ "w", newline=""
220
+ ) as file:
221
+ writer = csv.writer(file)
222
+ for question in range(len(question_list)):
223
+ # TODO: Shuffle answers according to row, keep correct answer in random section. Answer column is a number.
224
+ new_row = [question_list[question]["Question"]]
225
+ wrong_answers = list(question_list[question]["Wrong Answers"])
226
+ column = random.randint(1, len(wrong_answers) + 1)
227
+ new_row.append(column)
228
+ for i in range(1, len(wrong_answers) + 2):
229
+ if i == column:
230
+ new_row.append(question_list[question]["Answer"])
231
+ else:
232
+ new_row.append(wrong_answers.pop())
233
+ new_row.append(question_list[question]["Page"])
234
+ new_row.append(question_list[question]["Taxonomy"])
235
+ writer.writerow(new_row)