prd101-wd/model_testing
0
1import streamlit as st2from transformers import pipeline3 4# model repo ID5model_id = "prd101-wd/phi1_5-bankingqa-merged"6 7# Load model only once8@st.cache_resource9def load_model():10 #return pipeline("question-answering", model=model_id)11 return pipeline("text-generation", model=model_id, trust_remote_code=True)12 13# Create a text generation pipeline14pipe = load_model()15 16# Streamlit UI17st.title("Banking HelpDesk from Finetuned Phi1-5")18 19st.markdown("Ask a question and the fine-tuned Phi-1.5 model will answer.")20 21user_input = st.text_area("Your question:", height=100)22 23if st.button("Ask"):24 if user_input.strip():25 # Format the prompt like Alpaca-style26 prompt = f"### Instruction:\n{user_input}\n\n### Response:\n"27 output = pipe(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)28 29 # Process output30 if isinstance(output, list) and output:31 answer = output[0]['generated_text']32 # Extract only the response part33 if "### Response:" in answer:34 answer = answer.split("### Response:")[-1].strip()35 else:36 answer = "Unable to generate a response. Please try again."37 38 39 40 # if isinstance(output, list) and len(output) > 0 and "generated_text" in output[0]:41 # answer = output[0]["generated_text"]42 # else:43 # answer = "Unable to generate a response. Please try again."44 45 # Extract only the model's response (remove prompt part if included in output)46 #answer = output.split("### Response:")[-1].strip()47 # if isinstance(output, str):48 # answer = output.split("### Response:")[-1].strip()49 # else:50 # answer = "Unexpected output format. Please try again."51 52 st.markdown("### HelpdeskBot Answer:")53 st.success(answer)54 else:55 st.warning("Please enter a question.")56 