code_detector / app.py
RoAr777's picture
Update app.py
5042e4f
raw
history blame
856 Bytes
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
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:
"{}"
'''
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
def chatbot_model(m,history):
# Encode the prompt and generate response
input_ids = tokenizer.encode(prompt.format(m) + tokenizer.eos_token, return_tensors='pt')
outputs = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
# Decode the output
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
return decoded_output
iface = gr.ChatInterface(chatbot_model)
iface.launch()