Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- app.py +66 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import minichain
|
2 |
+
from dataclasses import fields, dataclass, is_dataclass
|
3 |
+
from typing import List
|
4 |
+
from enum import Enum
|
5 |
+
|
6 |
+
class ColorType(Enum):
|
7 |
+
RED = 1
|
8 |
+
GREEN = 2
|
9 |
+
BLUE = 3
|
10 |
+
|
11 |
+
@dataclass
|
12 |
+
class Color:
|
13 |
+
color: ColorType
|
14 |
+
object: str
|
15 |
+
explanation: str
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
# class StatType(Enum):
|
20 |
+
# POINTS = 1
|
21 |
+
# REBOUNDS = 2
|
22 |
+
# ASSISTS = 3
|
23 |
+
|
24 |
+
# @dataclass
|
25 |
+
# class Stat:
|
26 |
+
# value: int
|
27 |
+
# stat: StatType
|
28 |
+
|
29 |
+
# @dataclass
|
30 |
+
# class Player:
|
31 |
+
# player: str
|
32 |
+
# stats: List[Stat]
|
33 |
+
|
34 |
+
class T(minichain.TypedTemplatePrompt):
|
35 |
+
template_file = "stats.pmpt.tpl"
|
36 |
+
Out = Color
|
37 |
+
|
38 |
+
# print(T().show({"passage": "hello"}, '[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]'))
|
39 |
+
|
40 |
+
with minichain.start_chain("stats") as backend:
|
41 |
+
p = T(backend.OpenAI(max_tokens=512))
|
42 |
+
print(p({"passage": open("sixers.txt").read()}))
|
43 |
+
|
44 |
+
# def enum(x):
|
45 |
+
# d = {e.name: e.value for e in x}
|
46 |
+
# # d["__enum__"] = True
|
47 |
+
# return d
|
48 |
+
|
49 |
+
|
50 |
+
# def walk(x):
|
51 |
+
# print(x)
|
52 |
+
# if issubclass(x, Enum):
|
53 |
+
# return enum(x)
|
54 |
+
# if is_dataclass(x):
|
55 |
+
# return {y.name: walk(y.type) for y in fields(x)}
|
56 |
+
# return x.__name__
|
57 |
+
# # return [x for x in fields(B)]
|
58 |
+
# # print(x.name)
|
59 |
+
# # print(x.type)
|
60 |
+
# # if issubclass(x.type, Enum):
|
61 |
+
# # for e in x.type:
|
62 |
+
# # print(e.value)
|
63 |
+
# # print(e.name)
|
64 |
+
# # print(x)]
|
65 |
+
|
66 |
+
# print(walk(B))
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
git+https://github.com/srush/minichain
|
3 |
+
manifest-ml
|