j2moreno commited on
Commit
936709d
1 Parent(s): 49cdeed
Files changed (1) hide show
  1. app.py +8 -18
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
- if system_prompt != "":
50
- input_prompt = f"<s>[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n\n "
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
- # print(decoded_output)
66
 
67
- return decoded_output
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
- demo.queue(max_size=100).launch()
 
 
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)