rasyosef commited on
Commit
a50c2bb
·
verified ·
1 Parent(s): 24445e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -62,7 +62,7 @@ model_id = "microsoft/phi-2"
62
 
63
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
64
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32, device_map="cpu", trust_remote_code=True)
65
- phi2 = pipeline("text-generation", tokenizer=tokenizer, model=model, max_new_tokens=128, device_map="auto") # GPU
66
 
67
  phi2.tokenizer.pad_token_id = phi2.model.config.eos_token_id
68
  hf_model = HuggingFacePipeline(pipeline=phi2)
@@ -121,7 +121,9 @@ def upload_file(qa_chain):
121
  with gr.Blocks() as demo:
122
  gr.Markdown("""
123
  # RAG-Phi-2 Chatbot demo
124
- ### This chatbot uses the Phi-2 language model and retrieval augmented generation to allow you to add domain-specific knowledge by uploading a txt file.
 
 
125
  """)
126
 
127
  file_output = gr.File(label="txt file")
@@ -132,11 +134,6 @@ with gr.Blocks() as demo:
132
  )
133
  upload_button.upload(upload_file(qa_chain), upload_button, file_output)
134
 
135
- gr.Markdown("""
136
- ### Upload a txt file that contains the text data that you would like to augment the model with.
137
- If you don't have one, there is a default text data already loaded, the new Oppenheimer movie's wikipedia page.
138
- """)
139
-
140
  chatbot = gr.Chatbot(label="RAG Phi-2 Chatbot")
141
  msg = gr.Textbox(label="Message", placeholder="Enter text here")
142
 
 
62
 
63
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
64
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32, device_map="cpu", trust_remote_code=True)
65
+ phi2 = pipeline("text-generation", tokenizer=tokenizer, model=model, max_new_tokens=64, device_map="auto") # GPU
66
 
67
  phi2.tokenizer.pad_token_id = phi2.model.config.eos_token_id
68
  hf_model = HuggingFacePipeline(pipeline=phi2)
 
121
  with gr.Blocks() as demo:
122
  gr.Markdown("""
123
  # RAG-Phi-2 Chatbot demo
124
+ ### This chatbot uses the Phi-2 language model and retrieval augmented generation to allow you to add domain-specific knowledge by uploading a txt file.
125
+ ### Upload a txt file that contains the text data that you would like to augment the model with.
126
+ ### If you don't have one, there is a txt file already loaded, the new Oppenheimer movie's entire wikipedia page.
127
  """)
128
 
129
  file_output = gr.File(label="txt file")
 
134
  )
135
  upload_button.upload(upload_file(qa_chain), upload_button, file_output)
136
 
 
 
 
 
 
137
  chatbot = gr.Chatbot(label="RAG Phi-2 Chatbot")
138
  msg = gr.Textbox(label="Message", placeholder="Enter text here")
139