Spaces:
Running
on
Zero
Running
on
Zero
πwπ
Browse files
app.py
CHANGED
@@ -56,11 +56,17 @@ def prepare_prompt(query, retrieved_examples):
|
|
56 |
|
57 |
@spaces.GPU(duration=150)
|
58 |
def talk(message, history):
|
|
|
|
|
|
|
59 |
retrieved_examples = search(message)
|
|
|
60 |
message, metadata = prepare_prompt(message, retrieved_examples)
|
61 |
resources = HEADER
|
|
|
62 |
for title, url in metadata:
|
63 |
resources += f"[{title}]({url}), "
|
|
|
64 |
chat = []
|
65 |
for item in history:
|
66 |
chat.append({"role": "user", "content": item[0]})
|
@@ -70,6 +76,9 @@ def talk(message, history):
|
|
70 |
messages = tokenizer.apply_chat_template(
|
71 |
chat, tokenize=False, add_generation_prompt=True
|
72 |
)
|
|
|
|
|
|
|
73 |
# Tokenize the messages string
|
74 |
model_inputs = tokenizer([messages], return_tensors="pt").to(device)
|
75 |
streamer = TextIteratorStreamer(
|
@@ -88,11 +97,8 @@ def talk(message, history):
|
|
88 |
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
89 |
t.start()
|
90 |
|
91 |
-
# Initialize an empty string to store the generated text
|
92 |
-
partial_text = ""
|
93 |
for new_text in streamer:
|
94 |
partial_text += new_text
|
95 |
-
print("partial_text : ", partial_text)
|
96 |
yield partial_text
|
97 |
partial_text += resources
|
98 |
yield partial_text
|
|
|
56 |
|
57 |
@spaces.GPU(duration=150)
|
58 |
def talk(message, history):
|
59 |
+
print("history, ", history)
|
60 |
+
print("message ", message)
|
61 |
+
print("searching dataset ...")
|
62 |
retrieved_examples = search(message)
|
63 |
+
print("preparing prompt ...")
|
64 |
message, metadata = prepare_prompt(message, retrieved_examples)
|
65 |
resources = HEADER
|
66 |
+
print("preparing metadata ...")
|
67 |
for title, url in metadata:
|
68 |
resources += f"[{title}]({url}), "
|
69 |
+
print("preparing chat template ...")
|
70 |
chat = []
|
71 |
for item in history:
|
72 |
chat.append({"role": "user", "content": item[0]})
|
|
|
76 |
messages = tokenizer.apply_chat_template(
|
77 |
chat, tokenize=False, add_generation_prompt=True
|
78 |
)
|
79 |
+
# Initialize an empty string to store the generated text
|
80 |
+
partial_text = ""
|
81 |
+
yield partial_text
|
82 |
# Tokenize the messages string
|
83 |
model_inputs = tokenizer([messages], return_tensors="pt").to(device)
|
84 |
streamer = TextIteratorStreamer(
|
|
|
97 |
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
98 |
t.start()
|
99 |
|
|
|
|
|
100 |
for new_text in streamer:
|
101 |
partial_text += new_text
|
|
|
102 |
yield partial_text
|
103 |
partial_text += resources
|
104 |
yield partial_text
|