import gradio as gr from transformers import TFT5ForConditionalGeneration, RobertaTokenizer # load saved finetuned model model = TFT5ForConditionalGeneration.from_pretrained('ThoughtFocusAI/CodeGeneration-CodeT5-base') # load saved tokenizer tokenizer = RobertaTokenizer.from_pretrained('ThoughtFocusAI/CodeGeneration-CodeT5-base') def chat(chat_history, user_input): query = "Generate Python: " + user_input encoded_text = tokenizer(query, return_tensors='tf', padding='max_length', truncation=True, max_length=48) # inference generated_code = model.generate( encoded_text["input_ids"], attention_mask=encoded_text["attention_mask"], max_length=128 ) # decode generated tokens decoded_code = tokenizer.decode(generated_code.numpy()[0], skip_special_tokens=True) return chat_history + [(user_input, "
"+decoded_code+"
")]
my_theme = gr.Theme.from_hub('finlaymacklon/boxy_violet')
with gr.Blocks(title="Python Code Generation",theme=my_theme) as demo:
gr.HTML(value="