Spaces:
whan12
/
Running on L4

File size: 2,402 Bytes
ef95c3f
 
 
239e7f0
5a59d36
b624fdb
5a59d36
ef95c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import vllm
import torch
import gradio
import huggingface_hub
import os

huggingface_hub.login(token=os.environ["HF_TOKEN"])

# 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="uw-llm-factuality/FAVA") 
def result(passage, reference):
    prompt = [INPUT.format_map({"evidence":reference, "output":passage})]
    print(prompt)
    print("\n")
    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: #B2DCE5; border-bottom: 1px dotted;'>unverifiable</span>")
    output = output.replace("<invented>", "<span style='background-color: #BFE9B9; border-bottom: 1px dotted;'>invented</span>")
    output = output.replace("<subjective>", "<span style='background-color: #B5B7F5; border-bottom: 1px dotted;'>subjective</span>")
    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("Edited:", "")
    return f'<div style="font-weight: normal;">{output}</div>'; #output;

if __name__ == "__main__":
    demo = gradio.Interface(fn=result, inputs=["text", "text"], outputs="html")
    demo.launch(share=True)