Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- app.py +46 -0
- requirements.txt +3 -0
- stats.pmpt.tpl +6 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Information extraction from a typed data specification.
|
| 2 |
+
|
| 3 |
+
import minichain
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
from typing import List
|
| 6 |
+
from enum import Enum
|
| 7 |
+
|
| 8 |
+
# Data specification
|
| 9 |
+
|
| 10 |
+
# +
|
| 11 |
+
class StatType(Enum):
|
| 12 |
+
POINTS = 1
|
| 13 |
+
REBOUNDS = 2
|
| 14 |
+
ASSISTS = 3
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class Stat:
|
| 18 |
+
value: int
|
| 19 |
+
stat: StatType
|
| 20 |
+
|
| 21 |
+
@dataclass
|
| 22 |
+
class Player:
|
| 23 |
+
player: str
|
| 24 |
+
stats: List[Stat]
|
| 25 |
+
# -
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Code
|
| 29 |
+
|
| 30 |
+
class ExtractionPrompt(minichain.TypedTemplatePrompt):
|
| 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 |
+
'[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]')
|
| 43 |
+
|
| 44 |
+
# View the run log.
|
| 45 |
+
|
| 46 |
+
minichain.show_log("bash.log")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
git+https://github.com/srush/minichain
|
| 3 |
+
manifest-ml
|
stats.pmpt.tpl
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{typ | safe}}
|
| 2 |
+
|
| 3 |
+
{{passage}}
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
JSON Output:
|