Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile +24 -0
- README.md +5 -8
- app.py +54 -0
- requirements.txt +2 -0
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an alias for the base image for easier updates
|
2 |
+
FROM python:3.10 as base
|
3 |
+
|
4 |
+
# Set model
|
5 |
+
ENV MODEL=indischepartij/MiaLatte-Indo-Mistral-7b-GGUF
|
6 |
+
ENV QUANT=Q5_K_M
|
7 |
+
ENV CHAT_TEMPLATE=chatml
|
8 |
+
|
9 |
+
# Set the working directory
|
10 |
+
WORKDIR /app
|
11 |
+
|
12 |
+
# Install Python requirements
|
13 |
+
COPY ./requirements.txt /app/
|
14 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
15 |
+
|
16 |
+
# Download model
|
17 |
+
RUN MODEL_NAME_FILE=$(echo ${MODEL#*/} | tr '[:upper:]' '[:lower:]' | sed 's/-gguf$//') && \
|
18 |
+
wget https://huggingface.co/${MODEL}/resolve/main/${MODEL_NAME_FILE}.${QUANT}.gguf -O model.gguf
|
19 |
+
|
20 |
+
# Copy the rest of your application
|
21 |
+
COPY . .
|
22 |
+
|
23 |
+
# Command to run the application
|
24 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
@@ -1,13 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
7 |
-
sdk_version: 4.16.0
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: cc-by-nc-4.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: test
|
3 |
+
emoji: 😻
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: green
|
6 |
+
sdk: docker
|
|
|
|
|
7 |
pinned: false
|
|
|
8 |
---
|
9 |
|
10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
from llama_cpp import Llama
|
5 |
+
|
6 |
+
# Get environment variables
|
7 |
+
model_id = os.getenv('MODEL')
|
8 |
+
quant = os.getenv('QUANT')
|
9 |
+
chat_template = os.getenv('CHAT_TEMPLATE')
|
10 |
+
|
11 |
+
# Interface variables
|
12 |
+
model_name = model_id.split('/')[1].split('-GGUF')[0]
|
13 |
+
title = f"😻 {model_name}"
|
14 |
+
description = f"Chat with <a href=\"https://huggingface.co/{model_id}\">{model_name}</a> in GGUF format ({quant})!"
|
15 |
+
|
16 |
+
# Initialize the LLM
|
17 |
+
llm = Llama(model_path="model.gguf",
|
18 |
+
n_ctx=32768,
|
19 |
+
n_threads=2,
|
20 |
+
chat_format=chat_template)
|
21 |
+
|
22 |
+
# Function for streaming chat completions
|
23 |
+
def chat_stream_completion(message, history, system_prompt):
|
24 |
+
messages_prompts = [{"role": "system", "content": system_prompt}]
|
25 |
+
for human, assistant in history:
|
26 |
+
messages_prompts.append({"role": "user", "content": human})
|
27 |
+
messages_prompts.append({"role": "assistant", "content": assistant})
|
28 |
+
messages_prompts.append({"role": "user", "content": message})
|
29 |
+
|
30 |
+
response = llm.create_chat_completion(
|
31 |
+
messages=messages_prompts,
|
32 |
+
stream=True
|
33 |
+
)
|
34 |
+
message_repl = ""
|
35 |
+
for chunk in response:
|
36 |
+
if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
|
37 |
+
message_repl = message_repl + chunk['choices'][0]["delta"]["content"]
|
38 |
+
yield message_repl
|
39 |
+
|
40 |
+
# Gradio chat interface
|
41 |
+
gr.ChatInterface(
|
42 |
+
fn=chat_stream_completion,
|
43 |
+
title=title,
|
44 |
+
description=description,
|
45 |
+
additional_inputs=[gr.Textbox("Kamu adalah Mia, asisten AI yang pintar dan ceria.")],
|
46 |
+
additional_inputs_accordion="📝 System prompt",
|
47 |
+
examples=[
|
48 |
+
["sebutkan sumber daya alam yang termasuk energi fosil?"],
|
49 |
+
["Apa jenis skincare yang cocok untuk kulit sensitif?"],
|
50 |
+
["berapa hasil penghitungan dari 4^2+5"],
|
51 |
+
["jelaskan mengenai deret fibonacci"],
|
52 |
+
["Tolong berikan saya tutorial cara memasak Nasi Goreng"]
|
53 |
+
]
|
54 |
+
).queue().launch(server_name="0.0.0.0")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
llama-cpp-python
|
2 |
+
gradio
|