CoolFace
Apppublic

vaibhav1821/Text-to-code-Finetuned

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py27 linesDownload Raw Back to root
1import streamlit as st2from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline3 4# Load your model and tokenizer5@st.cache(allow_output_mutation=True)6def load_model():7    model_name = "abhishekyo/codellama2-finetuned-codex-fin7"8    tokenizer = AutoTokenizer.from_pretrained(model_name)9    model = AutoModelForCausalLM.from_pretrained(model_name)10    gen_pipeline = pipeline('text-generation', model=model, tokenizer=tokenizer, device=0)11    return gen_pipeline12 13gen_pipeline = load_model()14 15st.title('Text-to-Code Generator')16 17# Text input18user_input = st.text_area("Enter your text here:", height=200)19if st.button("Generate Code"):20    if user_input:21        with st.spinner("Generating code..."):22            results = gen_pipeline(user_input, max_length=512, num_return_sequences=1)23            generated_code = results[0]['generated_text']24        st.text_area("Generated Code:", value=generated_code, height=200)25    else:26        st.warning("Please enter some text to generate code.")27