File size: 1,609 Bytes
7f51a5a 2856ccc 7f51a5a f100939 cd3fe38 7f51a5a f100939 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
from datasets import load_dataset
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig, TrainingArguments, Trainer
import torch
import time
import evaluate
import pandas as pd
import numpy as np
import streamlit as st
st.title('Code Generation')
huggingface_dataset_name = "red1xe/code_instructions"
if st.button("Load Dataset"):
with st.spinner('Loading Dataset...'):
dataset = load_dataset(huggingface_dataset_name)
st.write(dataset)
if st.button("Load Model"):
with st.spinner('Loading Model...'):
model_name='google/flan-t5-base'
original_model = AutoModelForSeq2SeqLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_name)
x = st.slider('Select a sample', 0, 1000, 200)
if st.button("Show Sample"):
index = x
input = dataset['test'][index]['input']
instruction = dataset['test'][index]['instruction']
output = dataset['test'][index]['output']
prompt = f"""
Answer the following question.
{input} {instruction}
Answer:
"""
inputs = tokenizer(prompt, return_tensors='pt')
outputs = tokenizer.decode(
original_model.generate(
inputs["input_ids"],
max_new_tokens=200,
)[0],
skip_special_tokens=True
)
dash_line = '-'.join('' for x in range(100))
st.write(dash_line)
st.write(f'INPUT PROMPT:\n{prompt}')
st.write(dash_line)
st.write(f'BASELINE HUMAN SUMMARY:\n{output}\n')
st.write(dash_line)
st.write(f'MODEL GENERATION - ZERO SHOT:\n{outputs}') |