Spaces:
Sleeping
Sleeping
Upload model_consumer.py
Browse files- src/model_consumer.py +33 -0
src/model_consumer.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# model repo ID
|
| 5 |
+
model_id = "prd101-wd/phi1_5-bankingqa-merged"
|
| 6 |
+
|
| 7 |
+
# Load model only once
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_model():
|
| 10 |
+
return pipeline("question-answering", model=model_id)
|
| 11 |
+
|
| 12 |
+
# Create a text generation pipeline
|
| 13 |
+
pipe = load_model()
|
| 14 |
+
|
| 15 |
+
# Streamlit UI
|
| 16 |
+
st.title("Banking HelpDesk from Finetuned Phi1-5")
|
| 17 |
+
|
| 18 |
+
st.markdown("Ask a question and the fine-tuned Phi-1.5 model will answer.")
|
| 19 |
+
|
| 20 |
+
user_input = st.text_area("Your question:", height=100)
|
| 21 |
+
|
| 22 |
+
if st.button("Ask"):
|
| 23 |
+
if user_input.strip():
|
| 24 |
+
# Format the prompt like Alpaca-style
|
| 25 |
+
prompt = f"### Instruction:\n{user_input}\n\n### Response:\n"
|
| 26 |
+
output = pipe(prompt, max_new_tokens=200, do_sample=True)[0]["generated_text"]
|
| 27 |
+
|
| 28 |
+
# Extract only the model's response (remove prompt part if included in output)
|
| 29 |
+
answer = output.split("### Response:")[-1].strip()
|
| 30 |
+
st.markdown("### HelpdeskBot Answer:")
|
| 31 |
+
st.success(answer)
|
| 32 |
+
else:
|
| 33 |
+
st.warning("Please enter a question.")
|