Darka001 commited on
Commit
e166cde
·
verified ·
1 Parent(s): d381d58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -64,7 +64,7 @@ if compute_dtype == torch.float16 and use_4bit:
64
 
65
  model = AutoModelForCausalLM.from_pretrained(
66
  model_name, quantization_config=bnb_config)
67
- stop_list = [" \n\nAnswer:", " \n", " \n\n"]
68
  stop_token_ids = [tokenizer(x, return_tensors='pt', add_special_tokens=False)['input_ids'] for x in stop_list]
69
  stop_token_ids = [torch.LongTensor(x).to("cuda") for x in stop_token_ids]
70
 
@@ -132,11 +132,11 @@ rag_chain_with_source = RunnableParallel(
132
 
133
 
134
  def format_result(result):
135
- unique_videos = set((doc.metadata['act_number'], doc.metadata['act_url']) for doc in result['context'])
136
 
137
  # Create a plain text string where each title is followed by its URL
138
  titles_with_links = [
139
- f"{act_number}: {act_url}" for act_number, act_url in unique_videos
140
  ]
141
 
142
  # Join these entries with line breaks to form a clear list
@@ -220,7 +220,7 @@ def generate_answer(message, history, checkbox, subject_input, rubric, date_beg,
220
 
221
  result['answer'] =result['answer'].split("[/INST]")[-1].strip()
222
  formatted_results = format_result(result)
223
- return formatted_results
224
 
225
 
226
 
@@ -257,7 +257,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo :
257
  chatbot=gr.Chatbot(height=400, render = False),
258
  textbox = gr.Textbox(placeholder="Ввести питання", container=False, scale=7, render = False),
259
  title="Законодавчий Помічник",
260
- description="Спитай мене про будь-які регуляції в чинних законах України.",
261
  # # examples=["мобілізація", "земельна реформа", "екологія"],
262
 
263
  cache_examples=False,
 
64
 
65
  model = AutoModelForCausalLM.from_pretrained(
66
  model_name, quantization_config=bnb_config)
67
+ stop_list = [" \n\nAnswer:", " \n\n"]
68
  stop_token_ids = [tokenizer(x, return_tensors='pt', add_special_tokens=False)['input_ids'] for x in stop_list]
69
  stop_token_ids = [torch.LongTensor(x).to("cuda") for x in stop_token_ids]
70
 
 
132
 
133
 
134
  def format_result(result):
135
+ unique_videos = set((doc.metadata['title'], doc.metadata['act_url']) for doc in result['context'])
136
 
137
  # Create a plain text string where each title is followed by its URL
138
  titles_with_links = [
139
+ f"{title}: {act_url}" for title, act_url in unique_videos
140
  ]
141
 
142
  # Join these entries with line breaks to form a clear list
 
220
 
221
  result['answer'] =result['answer'].split("[/INST]")[-1].strip()
222
  formatted_results = format_result(result)
223
+ return result
224
 
225
 
226
 
 
257
  chatbot=gr.Chatbot(height=400, render = False),
258
  textbox = gr.Textbox(placeholder="Ввести питання", container=False, scale=7, render = False),
259
  title="Законодавчий Помічник",
260
+ description="Спитай мене про будь-які регуляції в чинних законах України, прийнятих VIII та IX скликанням ВРУ.",
261
  # # examples=["мобілізація", "земельна реформа", "екологія"],
262
 
263
  cache_examples=False,