Spaces:
Runtime error
Runtime error
Upload 11 files
Browse files- .gcloudignore +19 -0
- .gitattributes +35 -35
- Dockerfile +14 -14
- README.md +11 -11
- app.py +25 -25
- finetuning/finetuning.py +31 -0
- getans.py +20 -18
- requirements.txt +4 -4
.gcloudignore
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file specifies files that are *not* uploaded to Google Cloud
|
2 |
+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
|
3 |
+
# "#!include" directives (which insert the entries of the given .gitignore-style
|
4 |
+
# file at that point).
|
5 |
+
#
|
6 |
+
# For more information, run:
|
7 |
+
# $ gcloud topic gcloudignore
|
8 |
+
#
|
9 |
+
.gcloudignore
|
10 |
+
# If you would like to upload your .git directory, .gitignore file or files
|
11 |
+
# from your .gitignore file, remove the corresponding line
|
12 |
+
# below:
|
13 |
+
.git
|
14 |
+
.gitignore
|
15 |
+
|
16 |
+
# Python pycache:
|
17 |
+
__pycache__/
|
18 |
+
# Ignored by the build system
|
19 |
+
/setup.cfg
|
.gitattributes
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
FROM python:3.12.0
|
2 |
-
|
3 |
-
RUN useradd -m -u 10000 user
|
4 |
-
|
5 |
-
WORKDIR /app
|
6 |
-
|
7 |
-
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
-
|
9 |
-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
10 |
-
|
11 |
-
COPY --chown=user . /app
|
12 |
-
|
13 |
-
# Set gunicorn as entrypoint with default arguments
|
14 |
-
ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
|
|
1 |
+
FROM python:3.12.0
|
2 |
+
|
3 |
+
RUN useradd -m -u 10000 user
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
+
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
10 |
+
|
11 |
+
COPY --chown=user . /app
|
12 |
+
|
13 |
+
# Set gunicorn as entrypoint with default arguments
|
14 |
+
ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
---
|
2 |
-
title: Zing
|
3 |
-
emoji: 🌍
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: gray
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
license: llama2
|
9 |
-
---
|
10 |
-
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
---
|
2 |
+
title: Zing
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: gray
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
license: llama2
|
9 |
+
---
|
10 |
+
|
11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
-
from flask import Flask, render_template, request, jsonify
|
2 |
-
#from getans import get_response
|
3 |
-
|
4 |
-
app = Flask(__name__)
|
5 |
-
|
6 |
-
# Store chat history
|
7 |
-
chat_history = []
|
8 |
-
|
9 |
-
|
10 |
-
@app.route('/')
|
11 |
-
def index():
|
12 |
-
return render_template('index.html', chat_history=chat_history)
|
13 |
-
|
14 |
-
|
15 |
-
@app.route('/send_message', methods=['POST'])
|
16 |
-
def send_message():
|
17 |
-
user_message = request.form['message']
|
18 |
-
# Here you can process the user message and generate a response
|
19 |
-
bot_response = user_message#get_response(user_message, max_new_tokens=100)
|
20 |
-
chat_history.append({'user': user_message, 'bot': bot_response})
|
21 |
-
return jsonify(chat_history=chat_history)
|
22 |
-
|
23 |
-
|
24 |
-
if __name__ == '__main__':
|
25 |
-
app.run(debug=True)
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
#from getans import get_response
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
# Store chat history
|
7 |
+
chat_history = []
|
8 |
+
|
9 |
+
|
10 |
+
@app.route('/')
|
11 |
+
def index():
|
12 |
+
return render_template('index.html', chat_history=chat_history)
|
13 |
+
|
14 |
+
|
15 |
+
@app.route('/send_message', methods=['POST'])
|
16 |
+
def send_message():
|
17 |
+
user_message = request.form['message']
|
18 |
+
# Here you can process the user message and generate a response
|
19 |
+
bot_response = user_message#get_response(user_message, max_new_tokens=100)
|
20 |
+
chat_history.append({'user': user_message, 'bot': bot_response})
|
21 |
+
return jsonify(chat_history=chat_history)
|
22 |
+
|
23 |
+
|
24 |
+
if __name__ == '__main__':
|
25 |
+
app.run(debug=True)
|
finetuning/finetuning.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments
|
2 |
+
from huggingface_hub import login
|
3 |
+
token1="hf_"
|
4 |
+
token2="rPlNHzkJScHYmtGSaQPcaoKcjJGYQEpjLu"
|
5 |
+
login(token=token1+token2)
|
6 |
+
# Load pre-trained model and tokenizer (replace with desired model name)
|
7 |
+
model_name = "meta-llama/Llama-2-7b-chat-hf"
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
|
11 |
+
# Define training arguments (hyperparameters)
|
12 |
+
training_args = TrainingArguments(
|
13 |
+
output_dir='output', # Output directory for checkpoints etc.
|
14 |
+
per_device_train_batch_size=8, # Adjust based on your hardware
|
15 |
+
save_steps=10_000,
|
16 |
+
num_train_epochs=3, # Adjust training epochs as needed
|
17 |
+
)
|
18 |
+
|
19 |
+
# Load your training and validation data (specific to your chosen library)
|
20 |
+
train_dataset = "data/train.csv"
|
21 |
+
val_dataset = "data/val.csv"
|
22 |
+
# Create a Trainer object for fine-tuning
|
23 |
+
trainer = Trainer(
|
24 |
+
model=model,
|
25 |
+
args=training_args,
|
26 |
+
train_dataset=train_dataset, # Replace with your training data loader
|
27 |
+
eval_dataset=val_dataset, # Replace with your validation data loader
|
28 |
+
)
|
29 |
+
|
30 |
+
# Start fine-tuning
|
31 |
+
trainer.train()
|
getans.py
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
1 |
+
from mmap import mmap
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
+
from huggingface_hub import login
|
6 |
+
token1="hf_"
|
7 |
+
token2="rPlNHzkJScHYmtGSaQPcaoKcjJGYQEpjLu"
|
8 |
+
login(token=token1+token2)
|
9 |
+
|
10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
+
mm="finetuning/output/pytorch_model.bin"
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(mm)
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(mm)
|
14 |
+
|
15 |
+
def get_response(prompt, max_new_tokens=50):
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
17 |
+
outputs = model.generate(**inputs, max_new_tokens=max_new_tokens, temperature=0.0001, do_sample=True)
|
18 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True) # Use indexing instead of calling
|
19 |
+
ans=response.toString()
|
20 |
+
return ans
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
Flask~=3.0.3
|
2 |
-
gunicorn~=22.0.0
|
3 |
-
torch
|
4 |
-
transformers
|
5 |
huggingface_hub
|
|
|
1 |
+
Flask~=3.0.3
|
2 |
+
gunicorn~=22.0.0
|
3 |
+
torch
|
4 |
+
transformers
|
5 |
huggingface_hub
|