Spaces:
Running
Running
File size: 1,400 Bytes
2901f65 |
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 55 56 57 58 59 60 61 62 |
import streamlit as st
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
# Load the fine-tuned model and tokenizer
@st.cache_resource # Cache model to avoid reloading
def load_model():
model_directory = "C:/Users/DELL/Desktop/QC_streamlit/QC_fine_tuned_smollm2_360m_instruct_3_epoch"
model = AutoModelForCausalLM.from_pretrained(model_directory)
tokenizer = AutoTokenizer.from_pretrained(model_directory)
return model, tokenizer
# Load model and tokenizer
model, tokenizer = load_model()
# Create a pipeline
question_completion_pipeline = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
device=-1
)
# Streamlit UI
st.title("Question Completion Model")
st.write("Provide a partial question, and the model will complete it.")
partial_question = st.text_input("Enter a partial question:", "")
if st.button("Complete Question"):
if partial_question.strip():
output = question_completion_pipeline(
partial_question,
max_length=60,
num_return_sequences=1,
do_sample=True
)
completed_question = output[0]["generated_text"]
st.success(f"Completed Question: {completed_question}")
else:
st.warning("Please enter a partial question.")
|