Commit ·
1d28e28
1
Parent(s): 1c25d3a
App files added
Browse filesFiles changed (3)
- DockerfileAdded+33
- app.pyAdded+47
- requirements.txtAdded+2
123456789101112131415161718192021222324252627282930313233# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker# you will also find guides on how best to write your Dockerfile
FROM python:latest
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Install OllamaRUN curl -fsSL https://ollama.com/install.sh | sh
RUN ollama serve
# Set up a new user named "user" with user ID 1000RUN useradd -m -u 1000 user
# Switch to the "user" userUSER user
# Set home to the user's home directoryENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH
# Set the working directory to the user's home directoryWORKDIR $HOME/app
# Copy the current directory contents into the container at $HOME/app setting the owner to the userCOPY --chown=user . $HOME/app
CMD ["python", "app.py"]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import gradio as grfrom ollama import chat, ChatResponseimport subprocess
def interact(message: str, history: list): message_dct = { "role": "user", "content": message }
chat_history = [msg for msg in history] chat_history.append(message_dct)
response: ChatResponse = chat( model="deepseek-r1:1.5b", messages=chat_history, stream=True ) text_response = "" thinking_response = gr.ChatMessage(content="", metadata={"title":"Thinking Cloud"}) thinking = False
for chunk in response: bit = chunk["message"]["content"] if(bit == "<think>"): thinking = True continue elif(bit == "</think>"): thinking = False continue
if(thinking): thinking_response.content += bit else: text_response += bit final_response = [thinking_response, text_response] yield final_response
interface = gr.ChatInterface( fn=interact, type="messages", title="Deepseek-R1 Chat Interface")
if __name__ == "__main__": subprocess.run(["ollama", "run", "deepseek-r1:1.5b"]) interface.launch()12ollamagradioDockerfileAdded+33
app.pyAdded+47
requirements.txtAdded+2