CoolFace
Apppublic

SriBalajiS/codeGenerator-app

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py55 linesDownload Raw Back to root
1import streamlit as st2from unsloth import FastLanguageModel3from transformers import TextStreamer4 5# Streamlit input for the user to type a prompt6text = st.text_area("Enter the prompt:")7 8# Load the model (change the model path if needed)9max_seq_length = 204810dtype = None11load_in_4bit = True12 13model_name = "SriBalajiS/output"  # Replace with your own model path14model, tokenizer = FastLanguageModel.from_pretrained(15    model_name=model_name,16    max_seq_length=max_seq_length,17    dtype=dtype,18    load_in_4bit=load_in_4bit,19    device_map="auto",20)21 22# Prepare the Alpaca prompt format23alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.24 25### Instruction:26{}27 28### Input:29{}30 31### Response:32{}"""33 34# Set up the input for the model35inputs = tokenizer(36    [37        alpaca_prompt.format(38            text,  # User input39            "",    # Input field can be extended as needed40            "",    # Output field can be extended as needed41        )42    ],43    return_tensors="pt"44).to("cuda")45 46# Initialize the text streamer to display results47text_streamer = TextStreamer(tokenizer)48 49# Generate the response using the model50output = model.generate(**inputs, streamer=text_streamer, max_new_tokens=4096)51 52# Display the output in Streamlit53if output:54    st.json(output)55