drmasad commited on
Commit
83787dd
·
verified ·
1 Parent(s): e659be2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -97,16 +97,33 @@ for message in st.session_state.messages:
97
  if prompt := st.chat_input("Ask me anything about diabetes"):
98
  with st.chat_message("user"):
99
  st.markdown(prompt)
 
 
100
  st.session_state.messages.append({"role": "user", "content": prompt})
101
 
 
 
 
 
 
 
102
  with st.chat_message("assistant"):
 
103
  result = pipeline(
104
  task="text-generation",
105
  model=model,
106
  tokenizer=tokenizer,
107
  max_length=1024,
108
  temperature=temp_values
109
- )(prompt)
110
- response = result[0]['generated_text']
 
 
 
 
 
111
  st.markdown(response)
 
 
112
  st.session_state.messages.append({"role": "assistant", "content": response})
 
 
97
  if prompt := st.chat_input("Ask me anything about diabetes"):
98
  with st.chat_message("user"):
99
  st.markdown(prompt)
100
+
101
+ # Append user prompt to session state
102
  st.session_state.messages.append({"role": "user", "content": prompt})
103
 
104
+ # Structured instructions as used in your Colab example
105
+ instructions = "you are an expert endocrinologist. introduce your name as Dr Adam from the beginning then answer a patient query in a language the patient will understand"
106
+
107
+ # Combine structured instructions with user prompt
108
+ full_prompt = f"<s>[INST] {instructions} [/INST] {prompt}</s>"
109
+
110
  with st.chat_message("assistant"):
111
+ # Generate response using the pipeline with structured prompting
112
  result = pipeline(
113
  task="text-generation",
114
  model=model,
115
  tokenizer=tokenizer,
116
  max_length=1024,
117
  temperature=temp_values
118
+ )(full_prompt)
119
+
120
+ # Extract the answer from the generated text
121
+ generated_text = result[0]['generated_text']
122
+ response = generated_text.split("</s>")[-1].strip()
123
+
124
+ # Display the response
125
  st.markdown(response)
126
+
127
+ # Append assistant response to session state
128
  st.session_state.messages.append({"role": "assistant", "content": response})
129
+