abhika-m commited on
Commit
ef95c3f
1 Parent(s): fa5e6df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import vllm
2
+ import torch
3
+ import gradio
4
+
5
+ # Fava prompt
6
+ 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] "
7
+
8
+ model = vllm.LLM(model="uw-llm-factuality/FAVA")
9
+ def result(passage, reference):
10
+ prompt = [INPUT.format_map({"evidence":reference, "output":passage})]
11
+ print(prompt)
12
+ print("\n")
13
+ sampling_params = vllm.SamplingParams(
14
+ temperature=0,
15
+ top_p=1.0,
16
+ max_tokens=500,
17
+ )
18
+ outputs = model.generate(prompt, sampling_params)
19
+ outputs = [it.outputs[0].text for it in outputs]
20
+ output = outputs[0].replace("<mark>", "<span style='color: green; font-weight: bold;'> ")
21
+ output = output.replace("</mark>", " </span>")
22
+ output = output.replace("<delete>", "<span style='color: red; text-decoration: line-through;'>")
23
+ output = output.replace("</delete>", "</span>")
24
+ output = output.replace("<entity>", "<span style='background-color: #E9A2D9; border-bottom: 1px dotted;'>entity</span>")
25
+ output = output.replace("<relation>", "<span style='background-color: #F3B78B; border-bottom: 1px dotted;'>relation</span>")
26
+ output = output.replace("<contradictory>", "<span style='background-color: #FFFF9B; border-bottom: 1px dotted;'>contradictory</span>")
27
+ output = output.replace("<unverifiable>", "<span style='background-color: #B2DCE5; border-bottom: 1px dotted;'>unverifiable</span>")
28
+ output = output.replace("<invented>", "<span style='background-color: #BFE9B9; border-bottom: 1px dotted;'>invented</span>")
29
+ output = output.replace("<subjective>", "<span style='background-color: #B5B7F5; border-bottom: 1px dotted;'>subjective</span>")
30
+ output = output.replace("</entity>", "")
31
+ output = output.replace("</relation>", "")
32
+ output = output.replace("</contradictory>", "")
33
+ output = output.replace("</unverifiable>", "")
34
+ output = output.replace("</invented>", "")
35
+ output = output.replace("</subjective>", "")
36
+ output = output.replace("Edited:", "")
37
+ return f'<div style="font-weight: normal;">{output}</div>'; #output;
38
+
39
+ if __name__ == "__main__":
40
+ demo = gradio.Interface(fn=result, inputs=["text", "text"], outputs="html")
41
+ demo.launch(share=True)