Spaces:
Sleeping
Sleeping
Commit
·
34d088d
1
Parent(s):
afec6e3
Add app
Browse files- Dockerfile +28 -0
- LICENSE +21 -0
- README.md +1 -0
- app.py +46 -0
- requirements.txt +1 -0
Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11
|
2 |
+
|
3 |
+
# Set up a new user named "user" with user ID 1000
|
4 |
+
RUN useradd -m -u 1000 user
|
5 |
+
|
6 |
+
# Switch to the "user" user
|
7 |
+
USER user
|
8 |
+
|
9 |
+
# Set home to the user's home directory
|
10 |
+
ENV HOME=/home/user \
|
11 |
+
PATH=/home/user/.local/bin:$PATH
|
12 |
+
|
13 |
+
# Set the working directory to the user's home directory
|
14 |
+
WORKDIR $HOME/app
|
15 |
+
|
16 |
+
# Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
|
17 |
+
RUN pip install --no-cache-dir --upgrade pip
|
18 |
+
|
19 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
20 |
+
COPY --chown=user . $HOME/app
|
21 |
+
|
22 |
+
COPY --chown=user requirements.txt .
|
23 |
+
|
24 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
25 |
+
|
26 |
+
COPY --chown=user app.py app.py
|
27 |
+
|
28 |
+
ENTRYPOINT ["solara", "run", "app.py", "--host=0.0.0.0", "--port", "7860"]
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2024 Alonso Silva Allende
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README.md
CHANGED
@@ -6,6 +6,7 @@ colorTo: pink
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: mit
|
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: mit
|
9 |
+
app_port: 7860
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import solara
|
2 |
+
from typing import List
|
3 |
+
from typing_extensions import TypedDict
|
4 |
+
import time
|
5 |
+
|
6 |
+
class MessageDict(TypedDict):
|
7 |
+
role: str
|
8 |
+
content: str
|
9 |
+
|
10 |
+
# Streamed response emulator
|
11 |
+
def response_generator():
|
12 |
+
response = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
13 |
+
for word in response.split():
|
14 |
+
yield word + " "
|
15 |
+
time.sleep(0.05)
|
16 |
+
|
17 |
+
def add_chunk_to_ai_message(chunk: str):
|
18 |
+
messages.value = [
|
19 |
+
*messages.value[:-1],
|
20 |
+
{
|
21 |
+
"role": "assistant",
|
22 |
+
"content": messages.value[-1]["content"] + chunk,
|
23 |
+
},
|
24 |
+
]
|
25 |
+
|
26 |
+
messages: solara.Reactive[List[MessageDict]] = solara.reactive([])
|
27 |
+
@solara.component
|
28 |
+
def Page():
|
29 |
+
with solara.Column(style={"width": "70%", "padding": "50px"}):
|
30 |
+
user_message_count = len([m for m in messages.value if m["role"] == "user"])
|
31 |
+
def send(message):
|
32 |
+
messages.value = [*messages.value, {"role": "user", "content": message}]
|
33 |
+
def response(message):
|
34 |
+
messages.value = [*messages.value, {"role": "assistant", "content": ""}]
|
35 |
+
for chunk in response_generator():
|
36 |
+
add_chunk_to_ai_message(chunk)
|
37 |
+
def result():
|
38 |
+
if messages.value != []:
|
39 |
+
response(messages.value[-1]["content"])
|
40 |
+
result = solara.lab.use_task(result, dependencies=[user_message_count])
|
41 |
+
with solara.lab.ChatBox():
|
42 |
+
for item in messages.value:
|
43 |
+
if item["role"] != "user":
|
44 |
+
solara.Markdown(item["content"])
|
45 |
+
solara.lab.ChatInput(send_callback=send)
|
46 |
+
Page()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
solara==1.31.0
|