code_detector / app.py
RoAr777's picture
Update app.py
cfb525b
raw
history blame
789 Bytes
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import time
import gradio as gr
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-ul2")
tokenizer = AutoTokenizer.from_pretrained("google/flan-ul2")
prompt=''' Review the Following text as a human, who is tasked to Extract `Code Snippets` ,if any. If there are no Code Snippets in the below Text then return No CODE HIDDEN:
"{}"
'''
def reply(message, history):
m=message.replace('\n','')
m=m.replace('\t','')
inputs = tokenizer(prompt.format(m), return_tensors="pt")
outputs = model.generate(**inputs)
code=tokenizer.batch_decode(outputs, skip_special_tokens=True)
for i in range(len(code)):
time.sleep(0.3)
yield code[: i+1]
gr.ChatInterface(reply).queue().launch()