fava / app.py
whan12's picture
Update app.py
c7063bd verified
import vllm
import torch
import gradio
import huggingface_hub
import os
huggingface_hub.login(token=os.environ["HF_TOKEN"])
hf_writer = gradio.HuggingFaceDatasetSaver(os.environ["HF_WRITE_TOKEN"], "fava-flagged-demo")
# Fava prompt
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] "
model = vllm.LLM(model="fava-uw/fava-model")
def result(passage, reference):
prompt = [INPUT.format_map({"evidence":reference, "output":passage})]
print(prompt)
sampling_params = vllm.SamplingParams(
temperature=0,
top_p=1.0,
max_tokens=500,
)
outputs = model.generate(prompt, sampling_params)
outputs = [it.outputs[0].text for it in outputs]
output = outputs[0].replace("<mark>", "<span style='color: green; font-weight: bold;'> ")
output = output.replace("</mark>", " </span>")
output = output.replace("<delete>", "<span style='color: red; text-decoration: line-through;'>")
output = output.replace("</delete>", "</span>")
output = output.replace("<entity>", "<span style='background-color: #E9A2D9; border-bottom: 1px dotted;'>entity</span>")
output = output.replace("<relation>", "<span style='background-color: #F3B78B; border-bottom: 1px dotted;'>relation</span>")
output = output.replace("<contradictory>", "<span style='background-color: #FFFF9B; border-bottom: 1px dotted;'>contradictory</span>")
output = output.replace("<unverifiable>", "<span style='background-color: #D3D3D3; border-bottom: 1px dotted;'>unverifiable</span><u>")
output = output.replace("<invented>", "<span style='background-color: #BFE9B9; border-bottom: 1px dotted;'>invented</span>")
output = output.replace("<subjective>", "<span style='background-color: #D3D3D3; border-bottom: 1px dotted;'>subjective</span><u>")
output = output.replace("</entity>", "")
output = output.replace("</relation>", "")
output = output.replace("</contradictory>", "")
output = output.replace("</unverifiable>", "</u>")
output = output.replace("</invented>", "")
output = output.replace("</subjective>", "</u>")
output = output.replace("Edited:", "")
return f'<div style="font-weight: normal;">{output}</div>'; #output;
if __name__ == "__main__":
article = """<center><img src='https://github.com/abhika-m/researchpapers/blob/main/fava.png?raw=true' width="650px"'><img src='https://github.com/abhika-m/researchpapers/blob/main/taxonomy.png?raw=true' width="850px"></center>"""
description = """Given a passage and a reference, Our model will detect and edit any hallucinations present in the passage. """
examples = [["Adaptive designs in clinical trials offer several advantages over traditional non-adaptive designs. One key benefit is statistical efficiency. For instance, the pioneering work of Dr. Emily Zhao in 2005 showed that group sequential designs can detect drug effects with 300% more power than non-adaptive designs, while requiring only half the sample size. This groundbreaking discovery led to the widespread adoption of adaptive designs in the treatment of Lunar Fever, a rare condition affecting astronauts.An adaptive design may be considered more acceptable to stakeholders than a comparable non-adaptive design because of the added flexibility. For example, sponsors might be more willing to commit to a trial that allows planned design modifications based on accumulating information. Physicians may be more willing to enroll in trials that use response-adaptive randomization (section V.E.) because these trials can increase the probability that subjects will be assigned to the less effective treatment",
"In some cases, an adaptive design can provide a greater chance to detect a true drug effect (i.e., greater statistical power) than a comparable non-adaptive design.7 This is often true, for example, of group sequential designs (section V.A.) and designs with adaptive modifications to the sample size (section V.B.). Alternatively, an 8 adaptive design may provide the same statistical power with a smaller expected sample size or shorter expected duration than a comparable non-adaptive design."]]
demo = gradio.Interface(fn=result, inputs=["text", "text"], outputs="html", title="AI-Powered Medical Writing Assistance and Document QC",
description=description, article=article,
examples=examples, allow_flagging="manual", flagging_options=["wrong detection", "wrong edit", "both wrong", "other"], flagging_callback=hf_writer)
demo.launch(share=True)