Spaces:
Sleeping
Sleeping
Add compare app
Browse files- .gitignore +3 -0
- Dockerfile +59 -0
- README.md +2 -1
- palmyra-compare/.wf/components-page-0-c0f99a9e-5004-4e75-a6c6-36f17490b134.jsonl +22 -0
- palmyra-compare/.wf/components-root.jsonl +1 -0
- palmyra-compare/.wf/components-workflows_root.jsonl +1 -0
- palmyra-compare/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl +1 -0
- palmyra-compare/.wf/metadata.json +3 -0
- palmyra-compare/README.md +3 -0
- palmyra-compare/main.py +71 -0
- palmyra-compare/poetry.lock +0 -0
- palmyra-compare/static/README.md +8 -0
- palmyra-compare/static/custom.css +12 -0
- palmyra-compare/static/favicon.png +0 -0
- pyproject.toml +16 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
__pycache__
|
3 |
+
.env
|
Dockerfile
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Build stage
|
2 |
+
FROM python:3.11-slim-buster AS Build
|
3 |
+
|
4 |
+
# Set environment variables for Python and Poetry
|
5 |
+
ENV PYTHONUNBUFFERED=1 \
|
6 |
+
PIP_NO_CACHE_DIR=1 \
|
7 |
+
POETRY_NO_INTERACTION=1 \
|
8 |
+
POETRY_VIRTUALENVS_CREATE=false \
|
9 |
+
POETRY_VERSION=1.7.1
|
10 |
+
|
11 |
+
# Set the working directory in the container
|
12 |
+
WORKDIR /app
|
13 |
+
|
14 |
+
# Copy the dependencies file to the working directory
|
15 |
+
COPY ./pyproject.toml /app/
|
16 |
+
|
17 |
+
# Update, install dependencies, and prepare the Python environment
|
18 |
+
RUN apt-get update && \
|
19 |
+
apt-get install -y gcc g++ unixodbc-dev && \
|
20 |
+
pip install "poetry==$POETRY_VERSION" && \
|
21 |
+
poetry export --without-hashes --format requirements.txt --output requirements.txt && \
|
22 |
+
python3 -m pip wheel --no-cache-dir --no-deps -w /app/wheels -r requirements.txt
|
23 |
+
|
24 |
+
# Runtime stage
|
25 |
+
FROM python:3.11-slim-buster AS Run
|
26 |
+
|
27 |
+
# Set environment variables for Python and Poetry
|
28 |
+
ENV HOME=/home/user \
|
29 |
+
PATH=/home/user/.local/bin:$PATH
|
30 |
+
|
31 |
+
# Create a non-root user
|
32 |
+
RUN useradd -m -u 1000 user
|
33 |
+
|
34 |
+
# Switch to the non-root user
|
35 |
+
USER user
|
36 |
+
|
37 |
+
# Copy wheel files from the build stage
|
38 |
+
COPY --from=build /app/wheels $HOME/app/wheels
|
39 |
+
|
40 |
+
# Set the working directory to where the wheels are
|
41 |
+
WORKDIR $HOME/app/wheels
|
42 |
+
|
43 |
+
# Install the wheel files
|
44 |
+
RUN pip3 --no-cache-dir install *.whl
|
45 |
+
|
46 |
+
# Change app name here to copy the application files to the working directory
|
47 |
+
COPY --chown=user ./palmyra-compare $HOME/app
|
48 |
+
|
49 |
+
# Set the working directory to the application files
|
50 |
+
WORKDIR $HOME/app
|
51 |
+
|
52 |
+
# Specify the command to run the application
|
53 |
+
ENTRYPOINT [ "writer", "run" ]
|
54 |
+
|
55 |
+
# Expose the port the app runs on
|
56 |
+
EXPOSE 8080
|
57 |
+
|
58 |
+
# Set the default command to run the app
|
59 |
+
CMD [ ".", "--port", "8080", "--host", "0.0.0.0" ]
|
README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
---
|
2 |
title: Palmyra Creative
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
short_description: Compare responses from Palmyra X 004 and Palmyra Creative
|
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Palmyra Creative
|
3 |
+
emoji: 🖋️
|
4 |
colorFrom: green
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
short_description: Compare responses from Palmyra X 004 and Palmyra Creative
|
9 |
+
app_port: 8080
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
palmyra-compare/.wf/components-page-0-c0f99a9e-5004-4e75-a6c6-36f17490b134.jsonl
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{"id": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "type": "page", "content": {"cssClasses": "model-response", "pageMode": "compact"}, "handlers": {}, "isCodeManaged": false, "parentId": "root", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
|
2 |
+
{"id": "bebc5fe9-63a7-46a7-b0fa-62303555cfaf", "type": "header", "content": {"text": "Palmyra Comparison"}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
|
3 |
+
{"id": "mx2ph7hyrz2dmq17", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 1}
|
4 |
+
{"id": "3b2e0daziszd6kef", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "mx2ph7hyrz2dmq17", "position": 0}
|
5 |
+
{"id": "5nvbv0q0pn61zm6k", "type": "section", "content": {"containerBackgroundColor": "#E4E9FF", "isCollapsible": "yes", "title": "Palmyra X 004"}, "handlers": {}, "isCodeManaged": false, "parentId": "3b2e0daziszd6kef", "position": 0}
|
6 |
+
{"id": "xjztn0ul0mxuq1of", "type": "text", "content": {"text": "**Palmyra X 004** is our newest and most advanced language model with a large context window of up to 128,000 tokens. This model excels in processing and understanding complex tasks, making it ideal for workflow automation, coding tasks, and data analysis.", "useMarkdown": "yes"}, "handlers": {}, "isCodeManaged": false, "parentId": "5nvbv0q0pn61zm6k", "position": 0}
|
7 |
+
{"id": "ppg3ncuom2jj5rl5", "type": "section", "content": {"title": ""}, "handlers": {}, "isCodeManaged": false, "parentId": "3b2e0daziszd6kef", "position": 1}
|
8 |
+
{"id": "z42d3lavps0u2bi1", "type": "text", "content": {"alignment": "", "cssClasses": "model-response", "text": "@{palmyra-x-004-response}", "useMarkdown": "yes"}, "handlers": {}, "isCodeManaged": false, "parentId": "ppg3ncuom2jj5rl5", "position": 0}
|
9 |
+
{"id": "b99w95l47qi42mh0", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "mx2ph7hyrz2dmq17", "position": 1}
|
10 |
+
{"id": "81k8gmffjp5chsrd", "type": "section", "content": {"containerBackgroundColor": "#FFF4F1", "isCollapsible": "yes", "title": "Palmyra Creative"}, "handlers": {}, "isCodeManaged": false, "parentId": "b99w95l47qi42mh0", "position": 0}
|
11 |
+
{"id": "6z7srnyn32vf95vz", "type": "text", "content": {"text": "**Palmyra Creative** is Writer\u2019s purpose-built language model, engineered to elevate creative thinking and writing across diverse professional contexts. With capabilities that amplify originality and adaptability, it caters to industries and teams where innovation drives success. ", "useMarkdown": "yes"}, "handlers": {}, "isCodeManaged": false, "parentId": "81k8gmffjp5chsrd", "position": 0}
|
12 |
+
{"id": "beb792yvj93xyv5b", "type": "section", "content": {"title": ""}, "handlers": {}, "isCodeManaged": false, "parentId": "b99w95l47qi42mh0", "position": 1}
|
13 |
+
{"id": "du2eo5uxgqtvvrac", "type": "text", "content": {"alignment": "", "cssClasses": "model-response", "text": "@{palmyra-creative-response}", "useMarkdown": "yes"}, "handlers": {}, "isCodeManaged": false, "parentId": "beb792yvj93xyv5b", "position": 0}
|
14 |
+
{"id": "dnf3qmf96ttjz7ln", "type": "textinput", "binding": {"eventType": "wf-change", "stateRef": "user-prompt"}, "content": {"cssClasses": "prompt-input", "label": "", "placeholder": "Brainstorm with Palmyra here."}, "handlers": {"wf-change-finish": "handle_user_input"}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 2}
|
15 |
+
{"id": "mse4hifzxkrxu65f", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 3}
|
16 |
+
{"id": "r9rvh3iyjwas0467", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "mse4hifzxkrxu65f", "position": 0}
|
17 |
+
{"id": "prompt-left-button", "type": "button", "content": {"buttonColor": "#5551ff", "cssClasses": "prompt-button", "text": "@{prompt-left-button}"}, "handlers": {"wf-click": "handle_prompt_button"}, "isCodeManaged": false, "parentId": "r9rvh3iyjwas0467", "position": 0}
|
18 |
+
{"id": "w2t4ga6ax52pfvia", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "mse4hifzxkrxu65f", "position": 1}
|
19 |
+
{"id": "prompt-center-button", "type": "button", "content": {"buttonColor": "#241f31", "cssClasses": "prompt-button", "text": "@{prompt-center-button}"}, "handlers": {"wf-click": "handle_prompt_button"}, "isCodeManaged": false, "parentId": "w2t4ga6ax52pfvia", "position": 0}
|
20 |
+
{"id": "5x7gojqt67e68boz", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "mse4hifzxkrxu65f", "position": 2}
|
21 |
+
{"id": "prompt-right-button", "type": "button", "content": {"buttonColor": "#D4B2F7", "cssClasses": "prompt-button", "text": "@{prompt-right-button}"}, "handlers": {"wf-click": "handle_prompt_button"}, "isCodeManaged": false, "parentId": "5x7gojqt67e68boz", "position": 0}
|
22 |
+
{"id": "eg0jasykaie4je67", "type": "link", "content": {"rel": "noopener noreferrer", "target": "_blank", "text": "Build an app like this with Writer Framework.", "url": "https://github.com/writer/writer-framework"}, "handlers": {}, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 4}
|
palmyra-compare/.wf/components-root.jsonl
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"id": "root", "type": "root", "content": {"appName": "Palmyra Comparison"}, "handlers": {}, "isCodeManaged": false, "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
|
palmyra-compare/.wf/components-workflows_root.jsonl
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"id": "workflows_root", "type": "workflows_root", "content": {}, "handlers": {}, "isCodeManaged": false, "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
|
palmyra-compare/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"id": "lfltcky7l1fsm6j2", "type": "workflows_workflow", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "workflows_root", "position": 0}
|
palmyra-compare/.wf/metadata.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"writer_version": "0.8.2"
|
3 |
+
}
|
palmyra-compare/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
This app was created using Writer Framework.
|
2 |
+
|
3 |
+
To learn more about it, visit https://dev.writer.com/framework
|
palmyra-compare/main.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
|
3 |
+
import writer as wf
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
from writer import WriterState
|
6 |
+
from writerai import AsyncWriter
|
7 |
+
from writerai.types.chat_chat_params import Message
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
def handle_user_input(payload: str, state: WriterState) -> None:
|
12 |
+
asyncio.run(_ask_models(payload, state))
|
13 |
+
|
14 |
+
|
15 |
+
def handle_prompt_button(context: dict, state: WriterState) -> None:
|
16 |
+
state["user-prompt"] = state[context["target"]+'-full']
|
17 |
+
asyncio.run(_ask_models(state[context["target"]+'-full'], state))
|
18 |
+
|
19 |
+
|
20 |
+
async def _ask_models(prompt: str, state: WriterState) -> None:
|
21 |
+
state["palmyra-x-004-conversation"].append(Message(role="user", content=prompt))
|
22 |
+
state["palmyra-creative-conversation"].append(Message(role="user", content=prompt))
|
23 |
+
|
24 |
+
async_writer_client = AsyncWriter()
|
25 |
+
|
26 |
+
await asyncio.gather(
|
27 |
+
_perform_async_streaming(async_writer_client, "palmyra-x-004", state),
|
28 |
+
_perform_async_streaming(async_writer_client, "palmyra-creative", state),
|
29 |
+
)
|
30 |
+
|
31 |
+
|
32 |
+
async def _perform_async_streaming(client: AsyncWriter, model: str, state: WriterState) -> None:
|
33 |
+
try:
|
34 |
+
response = await client.chat.chat(
|
35 |
+
model=model,
|
36 |
+
messages=state[f"{model}" + "-conversation"],
|
37 |
+
stream=True,
|
38 |
+
max_tokens=16384
|
39 |
+
)
|
40 |
+
|
41 |
+
response_message = ""
|
42 |
+
state[f"{model}" + "-response"] = ""
|
43 |
+
|
44 |
+
async for message in response:
|
45 |
+
content = message.choices[0].delta.content
|
46 |
+
content = content if content is not None else ""
|
47 |
+
response_message += content
|
48 |
+
state[f"{model}" + "-response"] += content
|
49 |
+
|
50 |
+
state[f"{model}" + "-conversation"].append(Message(role="assistant", content=response_message))
|
51 |
+
|
52 |
+
except Exception as e:
|
53 |
+
response_message = "Something went wrong. Please, try again."
|
54 |
+
state[f"{model}" + "-conversation"].append(Message(role="assistant", content=response_message))
|
55 |
+
print(e)
|
56 |
+
|
57 |
+
initial_state = wf.init_state({
|
58 |
+
"palmyra-x-004-conversation": [],
|
59 |
+
"palmyra-x-004-response": "Model response will appear here...",
|
60 |
+
"palmyra-creative-conversation": [],
|
61 |
+
"palmyra-creative-response": "Model response will appear here...",
|
62 |
+
"user-prompt": "",
|
63 |
+
"prompt-left-button": "Brainstorm bakery strategies",
|
64 |
+
"prompt-left-button-full": "Imagine you're a struggling small-town bakery competing with a chain that opened across the street. Brainstorm unconventional strategies to win over customers without lowering prices.",
|
65 |
+
"prompt-center-button": "Explain AI to a high schooler",
|
66 |
+
"prompt-center-button-full": "Write a guide for a programmer who wants to explain their AI side project to a high schooler. The explanation must be engaging, simple, and use humorous analogies, while avoiding technical jargon.",
|
67 |
+
"prompt-right-button": "Zero gravity game",
|
68 |
+
"prompt-right-button-full": "Design a game that could only exist in zero gravity."
|
69 |
+
})
|
70 |
+
|
71 |
+
initial_state.import_stylesheet("style", "/static/custom.css")
|
palmyra-compare/poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
palmyra-compare/static/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Serving static files
|
2 |
+
|
3 |
+
You can use this folder to store files which will be served statically in the "/static" route.
|
4 |
+
|
5 |
+
This is useful to store images and other files which will be served directly to the user of your application.
|
6 |
+
|
7 |
+
For example, if you store an image named "myimage.jpg" in this folder, it'll be accessible as "static/myimage.jpg".
|
8 |
+
You can use this relative route as the source in an Image component.
|
palmyra-compare/static/custom.css
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.model-response {
|
2 |
+
height: 60vh !important;
|
3 |
+
overflow-y: auto !important;
|
4 |
+
}
|
5 |
+
|
6 |
+
.prompt-input{
|
7 |
+
max-width: 90vw !important;
|
8 |
+
}
|
9 |
+
|
10 |
+
.prompt-button{
|
11 |
+
width: 100vw !important;
|
12 |
+
}
|
palmyra-compare/static/favicon.png
ADDED
pyproject.toml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "palmyra-compare"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["dev-feedback@writer.com"]
|
6 |
+
readme = "README.md"
|
7 |
+
|
8 |
+
[tool.poetry.dependencies]
|
9 |
+
python = "^3.11"
|
10 |
+
writer = "0.8.2"
|
11 |
+
python-dotenv = "^1.0.1"
|
12 |
+
|
13 |
+
|
14 |
+
[build-system]
|
15 |
+
requires = ["poetry-core"]
|
16 |
+
build-backend = "poetry.core.masonry.api"
|