Merge branch 'main' of https://huggingface.co/hsb06/toghetherAi-model
Browse files- .gitattributes +35 -35
- app.py +74 -0
- config.json +1 -1
- generation_config.json +1 -1
- special_tokens_map.json +1 -1
- tokenizer_config.json +12 -0
.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
|
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from flask_cors import CORS
|
3 |
import torch
|
@@ -69,3 +70,76 @@ if __name__ == "__main__":
|
|
69 |
port = int(os.getenv("PORT", 5000))
|
70 |
logging.info(f"Starting Flask app on port {port}")
|
71 |
app.run(debug=True, host="0.0.0.0", port=port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<<<<<<< HEAD
|
2 |
from flask import Flask, request, jsonify
|
3 |
from flask_cors import CORS
|
4 |
import torch
|
|
|
70 |
port = int(os.getenv("PORT", 5000))
|
71 |
logging.info(f"Starting Flask app on port {port}")
|
72 |
app.run(debug=True, host="0.0.0.0", port=port)
|
73 |
+
=======
|
74 |
+
from flask import Flask, request, jsonify
|
75 |
+
from flask_cors import CORS
|
76 |
+
import torch
|
77 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
78 |
+
import logging
|
79 |
+
import os
|
80 |
+
|
81 |
+
# Logging setup
|
82 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
83 |
+
|
84 |
+
# Hugging Face Model Hub Repository
|
85 |
+
MODEL_REPO = "./" # Replace with your Hugging Face model repo name
|
86 |
+
|
87 |
+
# Load tokenizer and model from Hugging Face Model Hub
|
88 |
+
try:
|
89 |
+
logging.info("Loading model and tokenizer from Hugging Face Model Hub...")
|
90 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
|
91 |
+
dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
92 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_REPO, torch_dtype=dtype).to(
|
93 |
+
"cuda" if torch.cuda.is_available() else "cpu"
|
94 |
+
)
|
95 |
+
logging.info("Model loaded successfully.")
|
96 |
+
except Exception as e:
|
97 |
+
logging.error("Failed to load the model or tokenizer.", exc_info=True)
|
98 |
+
raise e
|
99 |
+
|
100 |
+
# Flask app initialization
|
101 |
+
app = Flask(__name__)
|
102 |
+
CORS(app) # Enable CORS
|
103 |
+
|
104 |
+
def generate_response(prompt):
|
105 |
+
"""Generate a response from the model given a prompt."""
|
106 |
+
try:
|
107 |
+
logging.debug(f"Generating response for prompt: {prompt}")
|
108 |
+
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
|
109 |
+
input_length = inputs.input_ids.shape[1]
|
110 |
+
outputs = model.generate(
|
111 |
+
**inputs, max_new_tokens=128, do_sample=True, temperature=0.7, top_p=0.7, top_k=50, return_dict_in_generate=True
|
112 |
+
)
|
113 |
+
token = outputs.sequences[0, input_length:]
|
114 |
+
output_str = tokenizer.decode(token, skip_special_tokens=True)
|
115 |
+
logging.debug(f"Generated response: {output_str}")
|
116 |
+
return output_str
|
117 |
+
except Exception as e:
|
118 |
+
logging.error("Error during response generation", exc_info=True)
|
119 |
+
return "Sorry, I encountered an error while generating the response."
|
120 |
+
|
121 |
+
@app.route('/chat', methods=['POST'])
|
122 |
+
def chat():
|
123 |
+
"""Endpoint to handle chat requests."""
|
124 |
+
try:
|
125 |
+
logging.debug("Received a POST request to /chat")
|
126 |
+
data = request.json
|
127 |
+
logging.debug(f"Request data: {data}")
|
128 |
+
|
129 |
+
if not data or "message" not in data:
|
130 |
+
return jsonify({"error": "Invalid request. 'message' field is required."}), 400
|
131 |
+
|
132 |
+
user_input = data.get("message", "")
|
133 |
+
prompt = f"<human>: {user_input}\n<bot>:"
|
134 |
+
response = generate_response(prompt)
|
135 |
+
return jsonify({"response": response}), 200
|
136 |
+
except Exception as e:
|
137 |
+
logging.error("Error in /chat endpoint", exc_info=True)
|
138 |
+
return jsonify({"error": "Internal server error", "message": str(e)}), 500
|
139 |
+
|
140 |
+
if __name__ == "__main__":
|
141 |
+
# Get the port from environment variable or default to 5000
|
142 |
+
port = int(os.getenv("PORT", 5000))
|
143 |
+
logging.info(f"Starting Flask app on port {port}")
|
144 |
+
app.run(debug=True, host="0.0.0.0", port=port)
|
145 |
+
>>>>>>> 6ff0da104f5a2eb5ee298dc0164db0c0b16215e2
|
config.json
CHANGED
@@ -22,4 +22,4 @@
|
|
22 |
"use_cache": true,
|
23 |
"use_parallel_residual": false,
|
24 |
"vocab_size": 50432
|
25 |
-
}
|
|
|
22 |
"use_cache": true,
|
23 |
"use_parallel_residual": false,
|
24 |
"vocab_size": 50432
|
25 |
+
}
|
generation_config.json
CHANGED
@@ -3,4 +3,4 @@
|
|
3 |
"bos_token_id": 0,
|
4 |
"eos_token_id": 0,
|
5 |
"transformers_version": "4.28.1"
|
6 |
-
}
|
|
|
3 |
"bos_token_id": 0,
|
4 |
"eos_token_id": 0,
|
5 |
"transformers_version": "4.28.1"
|
6 |
+
}
|
special_tokens_map.json
CHANGED
@@ -2,4 +2,4 @@
|
|
2 |
"bos_token": "<|endoftext|>",
|
3 |
"eos_token": "<|endoftext|>",
|
4 |
"unk_token": "<|endoftext|>"
|
5 |
-
}
|
|
|
2 |
"bos_token": "<|endoftext|>",
|
3 |
"eos_token": "<|endoftext|>",
|
4 |
"unk_token": "<|endoftext|>"
|
5 |
+
}
|
tokenizer_config.json
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
{
|
2 |
"add_prefix_space": false,
|
3 |
"bos_token": "<|endoftext|>",
|
@@ -7,3 +8,14 @@
|
|
7 |
"tokenizer_class": "GPTNeoXTokenizer",
|
8 |
"unk_token": "<|endoftext|>"
|
9 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<<<<<<< HEAD
|
2 |
{
|
3 |
"add_prefix_space": false,
|
4 |
"bos_token": "<|endoftext|>",
|
|
|
8 |
"tokenizer_class": "GPTNeoXTokenizer",
|
9 |
"unk_token": "<|endoftext|>"
|
10 |
}
|
11 |
+
=======
|
12 |
+
{
|
13 |
+
"add_prefix_space": false,
|
14 |
+
"bos_token": "<|endoftext|>",
|
15 |
+
"clean_up_tokenization_spaces": true,
|
16 |
+
"eos_token": "<|endoftext|>",
|
17 |
+
"model_max_length": 2048,
|
18 |
+
"tokenizer_class": "GPTNeoXTokenizer",
|
19 |
+
"unk_token": "<|endoftext|>"
|
20 |
+
}
|
21 |
+
>>>>>>> 6ff0da104f5a2eb5ee298dc0164db0c0b16215e2
|