Spaces:
Running
Running
feat: Init.
Browse files- .gitignore +4 -0
- Dockerfile +15 -0
- app.py +106 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
.mypy_cache
|
3 |
+
__py_cache__
|
4 |
+
```
|
Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
COPY app.py .
|
7 |
+
COPY requirements.txt .
|
8 |
+
|
9 |
+
RUN python -m venv venv
|
10 |
+
RUN ./venv/bin/pip install -r requirements.txt
|
11 |
+
|
12 |
+
ENV H2O_WAVE_LISTEN=":7860"
|
13 |
+
ENV H2O_WAVE_ADDRESS="http://127.0.0.1:7860"
|
14 |
+
|
15 |
+
CMD ["./venv/bin/wave", "run", "app.py", "--no-reload"]
|
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from h2o_wave import main, app, Q, ui, data
|
2 |
+
from gradio_client import Client
|
3 |
+
import ast
|
4 |
+
|
5 |
+
|
6 |
+
async def init_ui(q: Q) -> None:
|
7 |
+
q.page['meta'] = ui.meta_card(
|
8 |
+
box='',
|
9 |
+
layouts=[
|
10 |
+
ui.layout(breakpoint='xs', min_height='100vh', zones=[
|
11 |
+
ui.zone('main', size='1', direction=ui.ZoneDirection.ROW, zones=[
|
12 |
+
ui.zone('sidebar', size='250px'),
|
13 |
+
ui.zone('body', direction=ui.ZoneDirection.COLUMN, zones=[
|
14 |
+
ui.zone('title', size='55px'),
|
15 |
+
ui.zone('content', size='1'),
|
16 |
+
ui.zone('footer'),
|
17 |
+
]),
|
18 |
+
])
|
19 |
+
])
|
20 |
+
],
|
21 |
+
title='H2O GPT',
|
22 |
+
)
|
23 |
+
q.page['sidebar'] = ui.nav_card(
|
24 |
+
box='sidebar', color='primary', title='GPT Wave app', subtitle='Powered by H2O GPT',
|
25 |
+
value=f"#{q.args['#']}' if q.args['#'] else '#page1",
|
26 |
+
image='https://wave.h2o.ai/img/h2o-logo.svg', items=[
|
27 |
+
ui.nav_group('', items=[
|
28 |
+
ui.nav_item(name='wave-docs', label='Wave docs', path='https://wave.h2o.ai/'),
|
29 |
+
ui.nav_item(name='h2o-gpt', label='H2O GPT', path='https://github.com/h2oai/h2ogpt'),
|
30 |
+
ui.nav_item(name='fine-tune', label='LLM Studio', path='https://github.com/h2oai/h2o-llmstudio'),
|
31 |
+
ui.nav_item(name='more-models', label='More models', path='https://huggingface.co/h2oai'),
|
32 |
+
]),
|
33 |
+
],
|
34 |
+
secondary_items=[
|
35 |
+
ui.toggle(name='dark_mode', label='Dark mode', trigger=True),
|
36 |
+
ui.text('<center>Made with H2O Wave.</center>')
|
37 |
+
]
|
38 |
+
)
|
39 |
+
|
40 |
+
q.page['chatbot'] = ui.chatbot_card(
|
41 |
+
box=ui.box('content'),
|
42 |
+
data=data('content from_user', t='list'),
|
43 |
+
name='chatbot'
|
44 |
+
)
|
45 |
+
q.page['title'] = ui.section_card(
|
46 |
+
box='title',
|
47 |
+
title='',
|
48 |
+
subtitle='',
|
49 |
+
items=[
|
50 |
+
ui.dropdown(name='model', trigger=True, label='', value='gpt', choices=[
|
51 |
+
ui.choice(name='gpt', label='H2O GPT'),
|
52 |
+
ui.choice(name='falcon', label='h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v3'),
|
53 |
+
ui.choice(name='llama', label='h2oai/h2ogpt-research-oasst1-llama-65b'),
|
54 |
+
ui.choice(name='mpt', label='mosaicml/mpt-30b-instruct'),
|
55 |
+
]),
|
56 |
+
ui.button(name='clear', label='Clear', icon='Delete'),
|
57 |
+
],
|
58 |
+
)
|
59 |
+
|
60 |
+
|
61 |
+
@app('/')
|
62 |
+
async def serve(q: Q):
|
63 |
+
if not q.client.initialized:
|
64 |
+
await init_ui(q)
|
65 |
+
q.client.model_client = Client('https://gpt.h2o.ai/')
|
66 |
+
q.client.initialized = True
|
67 |
+
|
68 |
+
# A new message arrived.
|
69 |
+
if q.args.chatbot:
|
70 |
+
# Append user message.
|
71 |
+
q.page['chatbot'].data += [q.args.chatbot, True]
|
72 |
+
# Append bot response.
|
73 |
+
kwargs = dict(instruction_nochat=q.args.chatbot)
|
74 |
+
try:
|
75 |
+
res = q.client.model_client.predict(str(dict(kwargs)), api_name='/submit_nochat_api')
|
76 |
+
bot_res = ast.literal_eval(res)['response']
|
77 |
+
q.page['chatbot'].data += [bot_res, False]
|
78 |
+
except:
|
79 |
+
q.page['meta'] = ui.meta_card(box='', notification_bar=ui.notification_bar(
|
80 |
+
text='An error occurred during prediction. Please try later or a different model.',
|
81 |
+
type='error',
|
82 |
+
))
|
83 |
+
elif q.args.clear:
|
84 |
+
# Recreate the card.
|
85 |
+
q.page['chatbot'] = ui.chatbot_card(
|
86 |
+
box=ui.box('content'),
|
87 |
+
data=data('content from_user', t='list'),
|
88 |
+
name='chatbot'
|
89 |
+
)
|
90 |
+
elif q.args.dark_mode is not None:
|
91 |
+
q.page['meta'].theme = 'h2o-dark' if q.args.dark_mode else 'light'
|
92 |
+
q.page['sidebar'].color = 'card' if q.args.dark_mode else 'primary'
|
93 |
+
elif q.args.model:
|
94 |
+
try:
|
95 |
+
q.client.model_client = Client(f'https://{q.args.model}.h2o.ai/')
|
96 |
+
q.page['meta'] = ui.meta_card(box='', notification_bar=ui.notification_bar(
|
97 |
+
text='Model changed successfully.',
|
98 |
+
type='success',
|
99 |
+
))
|
100 |
+
except:
|
101 |
+
q.page['meta'] = ui.meta_card(box='', notification_bar=ui.notification_bar(
|
102 |
+
text='An error occurred while changing the model. Please try a different one.',
|
103 |
+
type='error',
|
104 |
+
))
|
105 |
+
|
106 |
+
await q.page.save()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
h2o-wave
|
2 |
+
gradio-client
|