JarrettYe commited on
Commit
35096e0
1 Parent(s): e900ade

preview memory state sequence

Browse files
Files changed (2) hide show
  1. app.py +27 -3
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import os
3
  import sys
@@ -5,10 +6,12 @@ import sys
5
  if os.environ.get("DEV_MODE"):
6
  # for local development
7
  sys.path.insert(0, os.path.abspath("../fsrs-optimizer/src/fsrs_optimizer/"))
8
- from fsrs_optimizer import Optimizer, DEFAULT_WEIGHT
9
 
10
 
11
- def interface_func(weights: str, ratings: str, request_retention: float) -> str:
 
 
12
  weights = weights.replace("[", "").replace("]", "")
13
  optimizer = Optimizer()
14
  optimizer.w = list(map(lambda x: float(x.strip()), weights.split(",")))
@@ -16,7 +19,26 @@ def interface_func(weights: str, ratings: str, request_retention: float) -> str:
16
  ratings.replace(" ", ""), request_retention
17
  )
18
  default_preview = optimizer.preview(request_retention)
19
- return test_sequence, default_preview
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
 
22
  iface = gr.Interface(
@@ -28,6 +50,7 @@ iface = gr.Interface(
28
  default=str(DEFAULT_WEIGHT)[1:-1],
29
  ),
30
  gr.inputs.Textbox(label="ratings", lines=1, default="3,3,3,3,1,3,3"),
 
31
  gr.inputs.Slider(
32
  label="Your Request Retention",
33
  minimum=0.6,
@@ -39,6 +62,7 @@ iface = gr.Interface(
39
  outputs=[
40
  gr.outputs.Textbox(label="test sequences"),
41
  gr.outputs.Textbox(label="default preview"),
 
42
  ],
43
  )
44
 
 
1
+ from typing import List, Tuple
2
  import gradio as gr
3
  import os
4
  import sys
 
6
  if os.environ.get("DEV_MODE"):
7
  # for local development
8
  sys.path.insert(0, os.path.abspath("../fsrs-optimizer/src/fsrs_optimizer/"))
9
+ from fsrs_optimizer import Optimizer, DEFAULT_WEIGHT, FSRS, lineToTensor
10
 
11
 
12
+ def interface_func(
13
+ weights: str, ratings: str, delta_ts: str, request_retention: float
14
+ ) -> str:
15
  weights = weights.replace("[", "").replace("]", "")
16
  optimizer = Optimizer()
17
  optimizer.w = list(map(lambda x: float(x.strip()), weights.split(",")))
 
19
  ratings.replace(" ", ""), request_retention
20
  )
21
  default_preview = optimizer.preview(request_retention)
22
+ if delta_ts:
23
+ s_history, d_history = memory_state_sequence(ratings, delta_ts, optimizer.w)
24
+ return (
25
+ test_sequence,
26
+ default_preview,
27
+ f"s: {(', '.join(s_history))}\nd: {', '.join(d_history)}",
28
+ )
29
+ return test_sequence, default_preview, ""
30
+
31
+
32
+ def memory_state_sequence(
33
+ r_history: str, t_history: str, weights: List[float]
34
+ ) -> Tuple[List[float], List[float]]:
35
+ fsrs = FSRS(weights)
36
+ line_tensor = lineToTensor(list(zip([t_history], [r_history]))[0]).unsqueeze(1)
37
+ outputs, _ = fsrs(line_tensor)
38
+ stabilities, difficulties = outputs.transpose(0, 1)[0].transpose(0, 1)
39
+ return map(lambda x: str(round(x, 2)), stabilities.tolist()), map(
40
+ lambda x: str(round(x, 2)), difficulties.tolist()
41
+ )
42
 
43
 
44
  iface = gr.Interface(
 
50
  default=str(DEFAULT_WEIGHT)[1:-1],
51
  ),
52
  gr.inputs.Textbox(label="ratings", lines=1, default="3,3,3,3,1,3,3"),
53
+ gr.inputs.Textbox(label="delta_ts", lines=1, optional=True),
54
  gr.inputs.Slider(
55
  label="Your Request Retention",
56
  minimum=0.6,
 
62
  outputs=[
63
  gr.outputs.Textbox(label="test sequences"),
64
  gr.outputs.Textbox(label="default preview"),
65
+ gr.outputs.Textbox(label="state history"),
66
  ],
67
  )
68
 
requirements.txt CHANGED
@@ -1 +1 @@
1
- FSRS-Optimizer==4.28.1
 
1
+ FSRS-Optimizer==4.28.2