Spaces:
Sleeping
Sleeping
removed Dockerfile
Browse files- Dockerfile +0 -34
- app.py +52 -28
- requirements.txt +0 -3
Dockerfile
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:latest
|
| 2 |
-
|
| 3 |
-
# Zaktualizuj pakiety i zainstaluj potrzebne narzędzia
|
| 4 |
-
RUN apt-get update && apt-get install -y curl openssh-client git python3 python3-pip
|
| 5 |
-
|
| 6 |
-
# Ustaw zmienną środowiskową, aby zainstalować odpowiednią wersję NumPy
|
| 7 |
-
ENV NUMPY_VERSION=1.21.6
|
| 8 |
-
|
| 9 |
-
# Zainstaluj wymagane biblioteki Python, w tym odpowiednią wersję NumPy
|
| 10 |
-
COPY requirements.txt .
|
| 11 |
-
RUN pip3 install numpy==$NUMPY_VERSION
|
| 12 |
-
RUN pip3 install -r requirements.txt
|
| 13 |
-
|
| 14 |
-
# Zainstaluj Ollamę
|
| 15 |
-
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 16 |
-
|
| 17 |
-
# Stwórz katalog na model i pobierz wybrany model z Hugging Face
|
| 18 |
-
RUN mkdir -p /root/.ollama/models && \
|
| 19 |
-
curl -L https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF/resolve/main/mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf -o /root/.ollama/models/mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf
|
| 20 |
-
|
| 21 |
-
# Utwórz Modelfile
|
| 22 |
-
RUN echo "FROM /root/.ollama/models/mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf" > /root/.ollama/Modelfile && \
|
| 23 |
-
echo "PARAMETER temperature 0.0" >> /root/.ollama/Modelfile && \
|
| 24 |
-
echo "TEMPLATE \"{{ if .System }}system\n{{ .System }}\n{{ end }}{{ if .Prompt }}user\n{{ .Prompt }}\n{{ end }}assistant\n\"" >> /root/.ollama/Modelfile
|
| 25 |
-
|
| 26 |
-
# Skopiuj pliki aplikacji
|
| 27 |
-
COPY app.py .
|
| 28 |
-
|
| 29 |
-
# Eksponuj porty dla Gradio i Ollama
|
| 30 |
-
EXPOSE 7860
|
| 31 |
-
EXPOSE 11434
|
| 32 |
-
|
| 33 |
-
# Uruchom aplikację Gradio oraz serwer Ollama
|
| 34 |
-
CMD ["sh", "-c", "export OLLAMA_HOST='0.0.0.0' && ollama serve & sleep 5 && ollama create my_custom_model -f /root/.ollama/Modelfile && python3 app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,35 +1,59 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
inputs=[
|
| 24 |
gr.inputs.Textbox(lines=2, placeholder="Wpisz prompt tutaj..."),
|
| 25 |
-
gr.inputs.Slider(0, 1, default=0.
|
| 26 |
-
gr.inputs.Slider(1, 500, default=
|
|
|
|
|
|
|
| 27 |
],
|
| 28 |
-
outputs="text"
|
| 29 |
-
title="Ollama Model Interface",
|
| 30 |
-
description="Interfejs do komunikacji z modelem Ollama za pomocą Gradio."
|
| 31 |
)
|
| 32 |
|
| 33 |
-
# Uruchom aplikację
|
| 34 |
if __name__ == "__main__":
|
| 35 |
-
|
|
|
|
| 1 |
+
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
+
|
| 4 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 5 |
+
|
| 6 |
+
def format_prompt(message, history):
|
| 7 |
+
prompt = "<s>"
|
| 8 |
+
for user_prompt, bot_response in history:
|
| 9 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
| 10 |
+
prompt += f" {bot_response}</s> "
|
| 11 |
+
prompt += f"[INST] {message} [/INST]"
|
| 12 |
+
return prompt
|
| 13 |
+
|
| 14 |
+
def generate(prompt, history, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
| 15 |
+
temperature = float(temperature)
|
| 16 |
+
if temperature < 1e-2:
|
| 17 |
+
temperature = 1e-2
|
| 18 |
+
top_p = float(top_p)
|
| 19 |
+
|
| 20 |
+
generate_kwargs = dict(
|
| 21 |
+
temperature=temperature,
|
| 22 |
+
max_new_tokens=max_new_tokens,
|
| 23 |
+
top_p=top_p,
|
| 24 |
+
repetition_penalty=repetition_penalty,
|
| 25 |
+
do_sample=True,
|
| 26 |
+
seed=42,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
formatted_prompt = format_prompt(prompt, history)
|
| 30 |
+
|
| 31 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 32 |
+
output = ""
|
| 33 |
+
|
| 34 |
+
for response in stream:
|
| 35 |
+
output += response.token.text
|
| 36 |
+
yield output
|
| 37 |
+
return output
|
| 38 |
+
|
| 39 |
+
# Definicja API Gradio
|
| 40 |
+
def predict(prompt, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
| 41 |
+
history = [] # lub inny sposób na przechowywanie historii rozmowy
|
| 42 |
+
output = generate(prompt, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 43 |
+
return output
|
| 44 |
+
|
| 45 |
+
# Utworzenie interfejsu API w Gradio
|
| 46 |
+
demo = gr.Interface(
|
| 47 |
+
fn=predict,
|
| 48 |
inputs=[
|
| 49 |
gr.inputs.Textbox(lines=2, placeholder="Wpisz prompt tutaj..."),
|
| 50 |
+
gr.inputs.Slider(0, 1, default=0.2, label="Temperature"),
|
| 51 |
+
gr.inputs.Slider(1, 500, default=256, label="Max New Tokens"),
|
| 52 |
+
gr.inputs.Slider(0, 1, default=0.95, label="Top P"),
|
| 53 |
+
gr.inputs.Slider(0.5, 2, default=1.0, label="Repetition Penalty")
|
| 54 |
],
|
| 55 |
+
outputs="text"
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
|
|
|
|
| 58 |
if __name__ == "__main__":
|
| 59 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
requests
|
| 3 |
-
numpy==1.21.6
|
|
|
|
|
|
|
|
|
|
|
|