prd101-wd commited on
Commit
0384c0c
·
verified ·
1 Parent(s): 6bf3bb3

Update model_consumer.py

Browse files
Files changed (1) hide show
  1. model_consumer.py +27 -8
model_consumer.py CHANGED
@@ -1,14 +1,33 @@
 
1
  from transformers import pipeline
2
 
3
- # Replace with your actual model repo ID
4
- #model_id = "prd101-wd/phi1_5-bankingqa-merged"
5
 
 
 
 
 
 
6
  # Create a text generation pipeline
7
- pipe = pipeline("question-answering", model="prd101-wd/phi1_5-bankingqa-merged")
8
 
9
- # Test the model with a prompt
10
- prompt = "I want to open an account with you. What do I need to do?"
11
- result = pipe(prompt, max_new_tokens=20)
12
 
13
- # Print the generated text
14
- print(result[0]["generated_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")