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("", " ")
output = output.replace("", " ")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "entity")
output = output.replace("", "relation")
output = output.replace("", "contradictory")
output = output.replace("", "unverifiable")
output = output.replace("", "invented")
output = output.replace("", "subjective")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("Edited:", "")
return f'
{output}
'; #output;
if __name__ == "__main__":
article = """"""
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)