import gradio as gr
from transformers import pipeline
import spaces
pipe = pipeline("text-generation", model="fava-uw/fava-model")
@spaces.GPU()
def chat(refrence: str, passage: str) -> str:
"""
Help to chat with fava
Args:
refrence: Pass the refrence text here
passage: main passage here
"""
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] "
outputs = pipe(text)
print(outputs)
output = outputs[0]['generated_text'].split("[Edited]")[1]
output = output.replace("", " ")
output = output.replace("", " ")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
output = output.replace("", "")
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}
';
with gr.Blocks() as demo:
gr.Markdown("# ExMC")
with gr.Row():
refrence = gr.Textbox(label="Refrence", placeholder="Enter your Refrence here")
passage = gr.Textbox(label="Passage", placeholder="Enter your passage")
submit_btn = gr.Button("Submit")
submit_btn.click(fn=chat, inputs=[refrence, passage], outputs=gr.HTML("Output result"))
demo.launch()