Spaces:
Running
Running
mateoluksenberg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -213,7 +213,6 @@ EXAMPLES = [
|
|
213 |
|
214 |
@spaces.GPU()
|
215 |
def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p: float = 1, top_k: int = 10, penalty: float = 1.0):
|
216 |
-
|
217 |
model = AutoModelForCausalLM.from_pretrained(
|
218 |
MODEL_ID,
|
219 |
torch_dtype=torch.bfloat16,
|
@@ -221,20 +220,9 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
221 |
trust_remote_code=True
|
222 |
)
|
223 |
|
224 |
-
print(f'
|
225 |
|
226 |
conversation = []
|
227 |
-
prompt_files = []
|
228 |
-
# if message["files"]:
|
229 |
-
# choice, contents = mode_load(message["files"][-1])
|
230 |
-
# if choice == "image":
|
231 |
-
# conversation.append({"role": "user", "image": contents, "content": message['text']})
|
232 |
-
# elif choice == "doc":
|
233 |
-
# format_msg = contents + "\n\n\n" + "{} files uploaded.\n" + message['text']
|
234 |
-
# conversation.append({"role": "user", "content": format_msg})
|
235 |
-
# else:
|
236 |
-
# choice = ""
|
237 |
-
# conversation.append({"role": "user", "image": "", "content": message['text']})
|
238 |
|
239 |
if message["file_content"]:
|
240 |
choice, contents = mode_load(message["file_content"])
|
@@ -248,11 +236,9 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
248 |
|
249 |
print(f"Conversation is -\n{conversation}")
|
250 |
|
251 |
-
|
252 |
-
print(f"Conversation is -\n{conversation}")
|
253 |
-
|
254 |
input_ids = tokenizer.apply_chat_template(conversation, tokenize=True, add_generation_prompt=True,
|
255 |
return_tensors="pt", return_dict=True).to(model.device)
|
|
|
256 |
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
|
257 |
|
258 |
generate_kwargs = dict(
|
@@ -274,17 +260,14 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
274 |
for new_text in streamer:
|
275 |
buffer += new_text
|
276 |
yield buffer
|
277 |
-
|
278 |
print("---------")
|
279 |
print("Text: ")
|
280 |
-
print(" ")
|
281 |
print(buffer)
|
282 |
-
print(" ")
|
283 |
print("---------")
|
284 |
|
285 |
|
286 |
|
287 |
-
|
288 |
# @spaces.GPU()
|
289 |
# def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096, top_p: float = 1, top_k: int = 10, penalty: float = 1.0):
|
290 |
# try:
|
|
|
213 |
|
214 |
@spaces.GPU()
|
215 |
def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p: float = 1, top_k: int = 10, penalty: float = 1.0):
|
|
|
216 |
model = AutoModelForCausalLM.from_pretrained(
|
217 |
MODEL_ID,
|
218 |
torch_dtype=torch.bfloat16,
|
|
|
220 |
trust_remote_code=True
|
221 |
)
|
222 |
|
223 |
+
print(f'Message is - {message}')
|
224 |
|
225 |
conversation = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
if message["file_content"]:
|
228 |
choice, contents = mode_load(message["file_content"])
|
|
|
236 |
|
237 |
print(f"Conversation is -\n{conversation}")
|
238 |
|
|
|
|
|
|
|
239 |
input_ids = tokenizer.apply_chat_template(conversation, tokenize=True, add_generation_prompt=True,
|
240 |
return_tensors="pt", return_dict=True).to(model.device)
|
241 |
+
|
242 |
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
|
243 |
|
244 |
generate_kwargs = dict(
|
|
|
260 |
for new_text in streamer:
|
261 |
buffer += new_text
|
262 |
yield buffer
|
263 |
+
|
264 |
print("---------")
|
265 |
print("Text: ")
|
|
|
266 |
print(buffer)
|
|
|
267 |
print("---------")
|
268 |
|
269 |
|
270 |
|
|
|
271 |
# @spaces.GPU()
|
272 |
# def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096, top_p: float = 1, top_k: int = 10, penalty: float = 1.0):
|
273 |
# try:
|