Commit
Β·
284bb1e
1
Parent(s):
c109086
Docker Update
Browse files- Dockerfile +31 -0
- README.md +3 -3
- app.py +44 -0
- requirements.txt +2 -0
Dockerfile
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:latest
|
5 |
+
|
6 |
+
WORKDIR /code
|
7 |
+
|
8 |
+
COPY ./requirements.txt /code/requirements.txt
|
9 |
+
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
+
|
12 |
+
# Install Ollama
|
13 |
+
RUN curl -fsSL https://ollama.com/install.sh | sh
|
14 |
+
|
15 |
+
# Set up a new user named "user" with user ID 1000
|
16 |
+
RUN useradd -m -u 1000 user
|
17 |
+
|
18 |
+
# Switch to the "user" user
|
19 |
+
USER user
|
20 |
+
|
21 |
+
# Set home to the user's home directory
|
22 |
+
ENV HOME=/home/user \
|
23 |
+
PATH=/home/user/.local/bin:$PATH
|
24 |
+
|
25 |
+
# Set the working directory to the user's home directory
|
26 |
+
WORKDIR $HOME/app
|
27 |
+
|
28 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
29 |
+
COPY --chown=user . $HOME/app
|
30 |
+
|
31 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
@@ -3,11 +3,11 @@ title: Microsoft Phi Interface
|
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
-
sdk:
|
7 |
-
sdk_version: 5.15.0
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
10 |
short_description: Gradio Interface for Microsoft Phi model
|
|
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
+
sdk: docker
|
|
|
|
|
7 |
pinned: false
|
8 |
short_description: Gradio Interface for Microsoft Phi model
|
9 |
+
models:
|
10 |
+
- microsoft/phi-2
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ollama import chat, ChatResponse
|
3 |
+
import subprocess
|
4 |
+
import time
|
5 |
+
|
6 |
+
model_id = "phi"
|
7 |
+
|
8 |
+
def interact(message: str, history: list):
|
9 |
+
message_dct = {
|
10 |
+
"role": "user",
|
11 |
+
"content": message
|
12 |
+
}
|
13 |
+
|
14 |
+
chat_history = [msg for msg in history]
|
15 |
+
chat_history.append(message_dct)
|
16 |
+
|
17 |
+
response: ChatResponse = chat(
|
18 |
+
model=model_id,
|
19 |
+
messages=chat_history,
|
20 |
+
stream=True
|
21 |
+
)
|
22 |
+
text_response = ""
|
23 |
+
|
24 |
+
for chunk in response:
|
25 |
+
bit = chunk["message"]["content"]
|
26 |
+
text_response += bit
|
27 |
+
yield text_response
|
28 |
+
|
29 |
+
interface = gr.ChatInterface(
|
30 |
+
fn=interact,
|
31 |
+
type="messages",
|
32 |
+
title="Microsoft Phi Chat Interface",
|
33 |
+
description="Model: Microsoft Phi-2 (2.7B params)"
|
34 |
+
)
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
print("\n\nStarting Ollama...\n\n")
|
38 |
+
subprocess.Popen(["ollama", "serve"])
|
39 |
+
time.sleep(10)
|
40 |
+
print("\n\nOllama started successfully!!\n\n\n\nTesting...\n\n")
|
41 |
+
subprocess.run(["ollama", "pull", model_id])
|
42 |
+
time.sleep(5)
|
43 |
+
print("\n\nMicrosoft Phi-2 started successfully!!\n\n")
|
44 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ollama
|
2 |
+
gradio
|