srush commited on
Commit
596c225
·
1 Parent(s): 25a1a07

Upload with huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # + tags=["hide_inp"]
2
+ desc = """
3
+ ### Word Problem Solver
4
+
5
+ Chain that solves a math word problem by first generating and then running Python code. [[Code](https://github.com/srush/MiniChain/blob/main/examples/math.py)]
6
+
7
+ (Adapted from Dust [maths-generate-code](https://dust.tt/spolu/a/d12ac33169))
8
+ """
9
+ # -
10
+
11
+ # $
12
+
13
+ from minichain import show, prompt, OpenAI, Python
14
+
15
+
16
+ @prompt(OpenAI(), template_file="math.pmpt.tpl")
17
+ def pal_prompt(model, question):
18
+ return model(dict(question=question))
19
+
20
+
21
+ @prompt(Python())
22
+ def python(model, inp):
23
+ return int(model(inp + "\nprint(solution())"))
24
+
25
+ def math_demo(question):
26
+ return python(pal_prompt(question))
27
+
28
+ # $
29
+
30
+ # + tags=["hide_inp"]
31
+ gradio = show(math_demo,
32
+ examples=["What is the sum of the powers of 3 (3^i) that are smaller than 100?",
33
+ "What is the sum of the 10 first positive integers?",
34
+ "Carla is downloading a 200 GB file. She can download 2 GB/minute, but 40% of the way through the download, the download fails. Then Carla has to restart the download from the beginning. How load did it take her to download the file in minutes?"],
35
+ out_type="markdown",
36
+ description=desc,
37
+ code=open("math_demo.py", "r").read().split("$")[1].strip().strip("#").strip(),
38
+ )
39
+ if __name__ == "__main__":
40
+ gradio.launch()
41
+ # -
42
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.21.0
2
+ git+https://github.com/srush/minichain@gradio
3
+ manifest-ml
4
+ faiss-cpu