Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
# app.py - Pennwick Honeybee Robot
|
3 |
#
|
4 |
# HuggingFace Spaces application to provide honeybee expertise
|
5 |
-
# with open-source models
|
6 |
#
|
7 |
-
# Mike Pastor February
|
8 |
|
9 |
|
10 |
import streamlit as st
|
@@ -35,8 +35,9 @@ DISPLAY_DIALOG_LINES = 6
|
|
35 |
SESSION_STARTED = False
|
36 |
|
37 |
# MODEL_NAME="deepset/roberta-base-squad2"
|
|
|
38 |
|
39 |
-
MODEL_NAME=
|
40 |
|
41 |
##################################################################################
|
42 |
def extract_pdf_text(pdf_docs):
|
@@ -185,35 +186,68 @@ def process_user_question(user_question):
|
|
185 |
#
|
186 |
# results_string += ("<p>" + "-- " + message.content + "</p>")
|
187 |
|
188 |
-
st.write(('Question: ' + user_question), unsafe_allow_html=True)
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
#
|
193 |
-
|
|
|
|
|
|
|
|
|
194 |
|
195 |
-
|
196 |
-
model_name = MODEL_NAME
|
197 |
|
198 |
-
|
199 |
-
# question = "What is the capital of France?"
|
200 |
-
# context = "France is a country located in Western Europe. It is bordered by the Atlantic Ocean to the west, the Mediterranean Sea to the south, and Belgium, Luxembourg, Germany, Switzerland, Italy, and Spain to the east and north."
|
201 |
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
-
|
206 |
-
|
207 |
|
208 |
-
#
|
209 |
-
|
210 |
-
|
211 |
|
212 |
-
|
|
|
|
|
|
|
213 |
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
-
html(results_string, height=
|
217 |
|
218 |
|
219 |
###################################################################################
|
|
|
2 |
# app.py - Pennwick Honeybee Robot
|
3 |
#
|
4 |
# HuggingFace Spaces application to provide honeybee expertise
|
5 |
+
# with open-source models
|
6 |
#
|
7 |
+
# Mike Pastor February 22, 2024
|
8 |
|
9 |
|
10 |
import streamlit as st
|
|
|
35 |
SESSION_STARTED = False
|
36 |
|
37 |
# MODEL_NAME="deepset/roberta-base-squad2"
|
38 |
+
#MODEL_NAME="BEE-spoke-data/TinyLlama-3T-1.1bee"
|
39 |
|
40 |
+
MODEL_NAME='HuggingFaceH4/zephyr-7b-beta'
|
41 |
|
42 |
##################################################################################
|
43 |
def extract_pdf_text(pdf_docs):
|
|
|
186 |
#
|
187 |
# results_string += ("<p>" + "-- " + message.content + "</p>")
|
188 |
|
|
|
189 |
|
190 |
+
#################################################################
|
191 |
+
# Track the overall time for training & submission preparation
|
192 |
+
# #
|
193 |
+
from datetime import datetime
|
194 |
+
global_now = datetime.now()
|
195 |
+
global_current_time = global_now.strftime("%H:%M:%S")
|
196 |
+
print("# app.py Starting up... - Current Time =", global_current_time)
|
197 |
+
st.write(('Question: ' + user_question + ' | ' + str( global_current_time )), unsafe_allow_html=True)
|
198 |
|
199 |
+
from transformers import pipeline
|
|
|
200 |
|
201 |
+
pipe = pipeline("conversational", "HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
202 |
|
203 |
+
# "Question: which technology is most recent? A)Cell phones B)Television C)Airplane Answer: "
|
204 |
+
messages = [
|
205 |
+
{
|
206 |
+
"role": "system",
|
207 |
+
"content": "You are a friendly chatbot who always responds in the style of a personal assistant",
|
208 |
+
},
|
209 |
+
{"role": "user",
|
210 |
+
"content": user_question },
|
211 |
+
]
|
212 |
|
213 |
+
st.write('Sending message to Model-> ', messages )
|
214 |
+
results_string = pipe(messages)
|
215 |
|
216 |
+
# st.write('results type= ', type( results_string) )
|
217 |
+
st.write('results= ', results_string)
|
218 |
+
# st.write('results ans= ', results_string[0])
|
219 |
|
220 |
+
# Mission Complete!
|
221 |
+
##################################################################################
|
222 |
+
global_later = datetime.now()
|
223 |
+
st.write("# Total EXECUTION Time =", (global_later - global_now), global_later)
|
224 |
|
225 |
+
#
|
226 |
+
# # Choose a question answering pipeline (e.g., 'question-answering')
|
227 |
+
# nlp = pipeline("question-answering")
|
228 |
+
#
|
229 |
+
# # Specify the model name or identifier (e.g., 'deepset/roberta-base-squad2')
|
230 |
+
# model_name = MODEL_NAME
|
231 |
+
#
|
232 |
+
# # Prepare the question and context (optional)
|
233 |
+
# # question = "What is the capital of France?"
|
234 |
+
# # context = "France is a country located in Western Europe. It is bordered by the Atlantic Ocean to the west, the Mediterranean Sea to the south, and Belgium, Luxembourg, Germany, Switzerland, Italy, and Spain to the east and north."
|
235 |
+
#
|
236 |
+
# context = "You are an expert Apiarist and answer all questions regarding Honeybees."
|
237 |
+
# # context = " "
|
238 |
+
#
|
239 |
+
# # Ask the question
|
240 |
+
# answer = nlp(question= ('Question: '+user_question), context=context, model=model_name)
|
241 |
+
#
|
242 |
+
# # Print the answer
|
243 |
+
# print(f"Answer: {answer['answer']}")
|
244 |
+
# print(f"Score: {answer['score']}")
|
245 |
+
#
|
246 |
+
# st.write( ('Answer= '+answer['answer']), unsafe_allow_html=True)
|
247 |
+
#
|
248 |
+
# results_string = answer['answer'] + ' - Probability= ' + str( answer['score'] )
|
249 |
|
250 |
+
# html(results_string, height=300, scrolling=True)
|
251 |
|
252 |
|
253 |
###################################################################################
|