Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -39,15 +39,26 @@ else:
|
|
39 |
|
40 |
@spaces.GPU(duration=150)
|
41 |
def chat(message, history, temperature,do_sample, max_tokens):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
start_time = time.time()
|
43 |
chat = []
|
44 |
-
for item in history:
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
chat.append({"role": "user", "content": message})
|
49 |
-
messages = tok.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
streamer = TextIteratorStreamer(
|
52 |
tok, timeout=10.0, skip_prompt=True, skip_special_tokens=True
|
53 |
)
|
|
|
39 |
|
40 |
@spaces.GPU(duration=150)
|
41 |
def chat(message, history, temperature,do_sample, max_tokens):
|
42 |
+
prompt_template = """
|
43 |
+
You are a helpful Agricultural assistant for farmers. You are given the following input. Please complete the response briefly.
|
44 |
+
## Question:
|
45 |
+
{}
|
46 |
+
|
47 |
+
## Response:
|
48 |
+
{}"""
|
49 |
start_time = time.time()
|
50 |
chat = []
|
51 |
+
# for item in history:
|
52 |
+
# chat.append({"role": "user", "content": item[0]})
|
53 |
+
# if item[1] is not None:
|
54 |
+
# chat.append({"role": "assistant", "content": item[1]})
|
55 |
+
# chat.append({"role": "user", "content": message})
|
56 |
+
# messages = tok.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
57 |
+
|
58 |
+
model_inputs = tok(prompt_template.format(
|
59 |
+
message, #input
|
60 |
+
"" # response
|
61 |
+
), return_tensors="pt").to(device)
|
62 |
streamer = TextIteratorStreamer(
|
63 |
tok, timeout=10.0, skip_prompt=True, skip_special_tokens=True
|
64 |
)
|