5m4ck3r commited on
Commit
a7e77b8
·
verified ·
1 Parent(s): 0db6fa7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import spaces
4
+
5
+ pipe = pipeline("text-generation", model="fava-uw/fava-model")
6
+
7
+ @spaces.GPU()
8
+ def chat(refrence: str, passage: str) -> str:
9
+ """
10
+ Help to chat with fava
11
+
12
+ Args:
13
+ refrence: Pass the refrence text here
14
+ passage: main passage here
15
+ """
16
+ text = f"Read the following references:\n{refrence}\nPlease identify all the errors in the following text using the information in the references provided and suggest edits if necessary:\n[Text] {passage}\n[Edited] "
17
+ outputs = pipe(text)
18
+ output_texts = [it.outputs[0].text for it in outputs]
19
+ output = outputs[0].replace("<mark>", "<span style='color: green; font-weight: bold;'> ")
20
+ output = output.replace("</mark>", " </span>")
21
+ output = output.replace("<delete>", "<span style='color: red; text-decoration: line-through;'>")
22
+ output = output.replace("</delete>", "</span>")
23
+ output = output.replace("<entity>", "<span style='background-color: #E9A2D9; border-bottom: 1px dotted;'></span>")
24
+ output = output.replace("<relation>", "<span style='background-color: #F3B78B; border-bottom: 1px dotted;'></span>")
25
+ output = output.replace("<contradictory>", "<span style='background-color: #FFFF9B; border-bottom: 1px dotted;'></span>")
26
+ output = output.replace("<unverifiable>", "<span style='background-color: #D3D3D3; border-bottom: 1px dotted;'></span><u>")
27
+ output = output.replace("<invented>", "<span style='background-color: #BFE9B9; border-bottom: 1px dotted;'></span>")
28
+ output = output.replace("<subjective>", "<span style='background-color: #D3D3D3; border-bottom: 1px dotted;'></span><u>")
29
+ output = output.replace("</entity>", "")
30
+ output = output.replace("</relation>", "")
31
+ output = output.replace("</contradictory>", "")
32
+ output = output.replace("</unverifiable>", "</u>")
33
+ output = output.replace("</invented>", "")
34
+ output = output.replace("</subjective>", "</u>")
35
+ output = output.replace("Edited:", "")
36
+ return f'<div style="font-weight: normal;">{output}</div>';
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("# ExMC")
40
+ with gr.Row():
41
+ refrence = gr.Textbox(label="Refrence", placeholder="Enter your Refrence here")
42
+ passage = gr.Textbox(label="Passage", placeholder="Enter your passage")
43
+ submit_btn = gr.Button("Submit")
44
+ output_text = gr.Textbox(label="Result")
45
+ submit_btn.click(fn=chat, inputs=[refrence, passage], outputs=output_text)
46
+
47
+ demo.launch()