pminervini commited on
Commit
c4c0ebe
1 Parent(s): 4467ed0
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -58,10 +58,13 @@ def search(query, index="pubmed", num_docs=3):
58
 
59
  return docs
60
 
61
- def analyse(text: str) -> str:
 
 
 
62
  model = vllm.LLM(model="fava-uw/fava-model")
63
  sampling_params = vllm.SamplingParams(temperature=0, top_p=1.0, max_tokens=500)
64
- outputs = model.generate(text, sampling_params)
65
  outputs = [it.outputs[0].text for it in outputs]
66
  output = outputs[0].replace("<mark>", "<span style='color: green; font-weight: bold;'> ")
67
  output = output.replace("</mark>", " </span>")
@@ -146,7 +149,7 @@ def rag_pipeline(prompt, index="pubmed", num_docs=3, model_name="HuggingFaceH4/z
146
  print('HF_RESPONSE', hf_response)
147
  response = hf_response[0]['generated_text']
148
 
149
- analysed_response = analyse(response)
150
 
151
  # Return the generated text and the documents
152
  return response, analysed_response, joined_docs
 
58
 
59
  return docs
60
 
61
+ def analyse(reference: str, passage: str) -> str:
62
+ fava_input = "Read the following references:\n{evidence}\nPlease identify all the errors in the following text using the information in the references provided and suggest edits if necessary:\n[Text] {output}\n[Edited] "
63
+ prompt = [fava_input.format_map({"evidence": reference, "output": passage})]
64
+
65
  model = vllm.LLM(model="fava-uw/fava-model")
66
  sampling_params = vllm.SamplingParams(temperature=0, top_p=1.0, max_tokens=500)
67
+ outputs = model.generate(prompt, sampling_params)
68
  outputs = [it.outputs[0].text for it in outputs]
69
  output = outputs[0].replace("<mark>", "<span style='color: green; font-weight: bold;'> ")
70
  output = output.replace("</mark>", " </span>")
 
149
  print('HF_RESPONSE', hf_response)
150
  response = hf_response[0]['generated_text']
151
 
152
+ analysed_response = analyse(joined_docs, response)
153
 
154
  # Return the generated text and the documents
155
  return response, analysed_response, joined_docs