Spaces:
Runtime error
Runtime error
samlam111
commited on
Commit
·
b7c86a5
1
Parent(s):
95e2b80
Random trial
Browse files- Dockerfile +31 -0
- app.py +78 -0
- requirements.txt +5 -0
Dockerfile
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use Python 3.10 as base image
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# Set working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Install system dependencies
|
8 |
+
RUN apt-get update && apt-get install -y \
|
9 |
+
build-essential \
|
10 |
+
git \
|
11 |
+
&& rm -rf /var/lib/apt/lists/*
|
12 |
+
|
13 |
+
# Copy requirements first to leverage Docker cache
|
14 |
+
COPY requirements.txt .
|
15 |
+
|
16 |
+
# Install Python dependencies
|
17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
18 |
+
|
19 |
+
# Copy the rest of the application
|
20 |
+
COPY . .
|
21 |
+
|
22 |
+
# Expose the port Gradio will run on
|
23 |
+
EXPOSE 7860
|
24 |
+
|
25 |
+
# Set environment variables
|
26 |
+
ENV PYTHONUNBUFFERED=1
|
27 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
28 |
+
ENV GRADIO_SERVER_PORT=7860
|
29 |
+
|
30 |
+
# Run the application
|
31 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
from transformers import TextStreamer
|
4 |
+
from peft import AutoPeftModelForCausalLM
|
5 |
+
from transformers import AutoTokenizer
|
6 |
+
|
7 |
+
|
8 |
+
"""
|
9 |
+
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
10 |
+
"""
|
11 |
+
|
12 |
+
model_name_or_path = "samlama111/lora_model"
|
13 |
+
|
14 |
+
# client = InferenceClient(model_name_or_path)
|
15 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
16 |
+
model_name_or_path, # YOUR MODEL YOU USED FOR TRAINING
|
17 |
+
load_in_4bit = True,
|
18 |
+
device_map = "auto",
|
19 |
+
)
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
21 |
+
|
22 |
+
def respond(
|
23 |
+
message,
|
24 |
+
history: list[tuple[str, str]],
|
25 |
+
system_message,
|
26 |
+
max_tokens,
|
27 |
+
temperature,
|
28 |
+
top_p,
|
29 |
+
):
|
30 |
+
messages = [{"role": "system", "content": system_message}]
|
31 |
+
|
32 |
+
for val in history:
|
33 |
+
if val[0]:
|
34 |
+
messages.append({"role": "user", "content": val[0]})
|
35 |
+
if val[1]:
|
36 |
+
messages.append({"role": "assistant", "content": val[1]})
|
37 |
+
|
38 |
+
messages.append({"role": "user", "content": message})
|
39 |
+
|
40 |
+
response = ""
|
41 |
+
|
42 |
+
inputs = tokenizer.apply_chat_template(messages, tokenize = True, add_generation_prompt = True, return_tensors = "pt")
|
43 |
+
|
44 |
+
text_streamer = TextStreamer(tokenizer)
|
45 |
+
# TODO: Doesn't stream ATM
|
46 |
+
for message in model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 1024, use_cache = True):
|
47 |
+
# Decode the tensor to a string
|
48 |
+
decoded_message = tokenizer.decode(message, skip_special_tokens=True)
|
49 |
+
|
50 |
+
# Manually getting the response
|
51 |
+
response = decoded_message.split("assistant")[-1].strip() # Extract only the assistant's response
|
52 |
+
print(response)
|
53 |
+
|
54 |
+
yield response
|
55 |
+
|
56 |
+
|
57 |
+
"""
|
58 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
59 |
+
"""
|
60 |
+
demo = gr.ChatInterface(
|
61 |
+
respond,
|
62 |
+
additional_inputs=[
|
63 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
64 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
65 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
66 |
+
gr.Slider(
|
67 |
+
minimum=0.1,
|
68 |
+
maximum=1.0,
|
69 |
+
value=0.95,
|
70 |
+
step=0.05,
|
71 |
+
label="Top-p (nucleus sampling)",
|
72 |
+
),
|
73 |
+
],
|
74 |
+
)
|
75 |
+
|
76 |
+
|
77 |
+
if __name__ == "__main__":
|
78 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
huggingface_hub==0.26.2
|
2 |
+
gradio
|
3 |
+
https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_multi-backend-refactor/bitsandbytes-0.44.1.dev0-py3-none-manylinux_2_24_x86_64.whl
|
4 |
+
transformers
|
5 |
+
peft
|