Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- app.py +30 -15
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
-
# Information extraction from a typed data specification.
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from dataclasses import dataclass
|
5 |
from typing import List
|
6 |
from enum import Enum
|
@@ -25,22 +34,28 @@ class Player:
|
|
25 |
# -
|
26 |
|
27 |
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
template_file = "stats.pmpt.tpl"
|
32 |
-
Out = Player
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
with minichain.start_chain("stats") as backend:
|
36 |
-
p = ExtractionPrompt(backend.OpenAI(max_tokens=512))
|
37 |
-
article = open("sixers.txt").read()
|
38 |
-
for player in p({"passage": article}):
|
39 |
-
print(player)
|
40 |
|
41 |
-
ExtractionPrompt().show({"passage": "Harden had 10 rebounds."},
|
42 |
-
|
43 |
|
44 |
-
# View the run log.
|
45 |
|
46 |
-
minichain.show_log("bash.log")
|
|
|
|
|
1 |
|
2 |
+
desc = """
|
3 |
+
### Typed Extraction
|
4 |
+
|
5 |
+
Information extraction that is automatically generated from a typed specification. [[Code](https://github.com/srush/MiniChain/blob/main/examples/stats.py)]
|
6 |
+
|
7 |
+
(Novel to MiniChain)
|
8 |
+
"""
|
9 |
+
|
10 |
+
# $
|
11 |
+
|
12 |
+
from minichain import prompt, show, type_to_prompt, OpenAI
|
13 |
from dataclasses import dataclass
|
14 |
from typing import List
|
15 |
from enum import Enum
|
|
|
34 |
# -
|
35 |
|
36 |
|
37 |
+
@prompt(OpenAI(), template_file="stats.pmpt.tpl", parser="json")
|
38 |
+
def stats(model, passage):
|
39 |
+
out = model(dict(passage=passage, typ=type_to_prompt(Player)))
|
40 |
+
return [Player(**j) for j in out]
|
41 |
|
42 |
+
# $
|
|
|
|
|
43 |
|
44 |
+
article = open("sixers.txt").read()
|
45 |
+
gradio = show(lambda passage: stats(passage),
|
46 |
+
examples=[article],
|
47 |
+
subprompts=[stats],
|
48 |
+
out_type="json",
|
49 |
+
description=desc,
|
50 |
+
code=open("stats.py", "r").read().split("$")[1].strip().strip("#").strip(),
|
51 |
+
)
|
52 |
+
if __name__ == "__main__":
|
53 |
+
gradio.launch()
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
# ExtractionPrompt().show({"passage": "Harden had 10 rebounds."},
|
57 |
+
# '[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]')
|
58 |
|
59 |
+
# # View the run log.
|
60 |
|
61 |
+
# minichain.show_log("bash.log")
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
-
gradio
|
2 |
git+https://github.com/srush/minichain@gradio
|
3 |
manifest-ml
|
|
|
|
1 |
+
gradio==3.21.0
|
2 |
git+https://github.com/srush/minichain@gradio
|
3 |
manifest-ml
|
4 |
+
faiss-cpu
|