Spaces:
Runtime error
Runtime error
Update
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
|
|
6 |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
# iface.launch()
|
8 |
|
9 |
-
import spaces
|
10 |
import torch
|
11 |
from transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArguments, pipeline, set_seed
|
12 |
|
@@ -42,29 +42,18 @@ examples=[
|
|
42 |
# else:
|
43 |
# print("You downvoted this response: " + data.value)
|
44 |
|
45 |
-
@spaces.GPU
|
46 |
def generate_response(message, chatbot, system_prompt="",):
|
47 |
set_seed(SEED)
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
else:
|
52 |
-
input_prompt = f"<s>[INST] "
|
53 |
-
|
54 |
-
for interaction in chatbot:
|
55 |
-
input_prompt = input_prompt + str(interaction[0]) + " [/INST] " + str(interaction[1]) + " </s><s>[INST] "
|
56 |
-
|
57 |
-
input_prompt = input_prompt + str(message) + " [/INST] "
|
58 |
-
print(input_prompt)
|
59 |
-
|
60 |
-
tokenized_prompt = tokenizer(input_prompt, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
61 |
-
# print(tokenized_prompt)
|
62 |
|
63 |
output_sequences = model.generate(**tokenized_prompt, max_length=1024, num_return_sequences=1)
|
64 |
decoded_output = tokenizer.decode(output_sequences[0], skip_special_tokens=True)
|
65 |
-
|
66 |
|
67 |
-
|
68 |
|
69 |
chatbot_stream = gr.Chatbot()
|
70 |
chat_interface_stream = gr.ChatInterface(generate_response,
|
@@ -84,4 +73,5 @@ with gr.Blocks() as demo:
|
|
84 |
# chatbot_stream.like(vote, None, None)
|
85 |
chat_interface_stream.render()
|
86 |
|
87 |
-
|
|
|
|
6 |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
# iface.launch()
|
8 |
|
9 |
+
# import spaces
|
10 |
import torch
|
11 |
from transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArguments, pipeline, set_seed
|
12 |
|
|
|
42 |
# else:
|
43 |
# print("You downvoted this response: " + data.value)
|
44 |
|
45 |
+
# @spaces.GPU
|
46 |
def generate_response(message, chatbot, system_prompt="",):
|
47 |
set_seed(SEED)
|
48 |
|
49 |
+
tokenized_prompt = tokenizer(message, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
50 |
+
print(tokenized_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
output_sequences = model.generate(**tokenized_prompt, max_length=1024, num_return_sequences=1)
|
53 |
decoded_output = tokenizer.decode(output_sequences[0], skip_special_tokens=True)
|
54 |
+
print(decoded_output)
|
55 |
|
56 |
+
yield decoded_output
|
57 |
|
58 |
chatbot_stream = gr.Chatbot()
|
59 |
chat_interface_stream = gr.ChatInterface(generate_response,
|
|
|
73 |
# chatbot_stream.like(vote, None, None)
|
74 |
chat_interface_stream.render()
|
75 |
|
76 |
+
if __name__ == "__main__":
|
77 |
+
demo.queue().launch(share=True)
|