Spaces:
Sleeping
Sleeping
Sandaruth
commited on
Commit
·
9a9ff62
1
Parent(s):
6709c06
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from model import Web_qa
|
3 |
+
from color import print_colorful_msg
|
4 |
+
import time
|
5 |
+
|
6 |
+
def chatbot_response(user_input): # Open AI GPT-3 and Google T5
|
7 |
+
start_time = time.time()
|
8 |
+
print_colorful_msg(f"User Input: {user_input}", color='green')
|
9 |
+
res = Web_qa(user_input)
|
10 |
+
response = res['result']
|
11 |
+
metadata = [i.metadata for i in res.get("source_documents", [])]
|
12 |
+
end_time = time.time()
|
13 |
+
response_time = end_time - start_time
|
14 |
+
print_colorful_msg(f"Response Time: {response_time} seconds", color='yellow')
|
15 |
+
return response, metadata, res.get('source_documents', [])
|
16 |
+
|
17 |
+
# def chatbot_response(user_input): # Hugging Face Misral model
|
18 |
+
# start_time = time.time()
|
19 |
+
# print_colorful_msg(f"User Input: {user_input}", color='green')
|
20 |
+
# res = Web_qa(user_input)
|
21 |
+
# print_colorful_msg(f"Response: {res}", color='blue')
|
22 |
+
# response = res["result"].split(": Let me think about it...")[-1]
|
23 |
+
# metadata = [i.metadata for i in res.get("source_documents", [])]
|
24 |
+
# end_time = time.time()
|
25 |
+
# response_time = end_time - start_time
|
26 |
+
# print_colorful_msg(f"Response Time: {response_time} seconds", color='yellow')
|
27 |
+
# return response, metadata, res.get('source_documents', [])
|
28 |
+
|
29 |
+
def main():
|
30 |
+
print_colorful_msg("Starting chatbot main function ...", color='blue')
|
31 |
+
st.title("Simple Chatbot")
|
32 |
+
|
33 |
+
user_input = st.text_input("Enter your message:")
|
34 |
+
if st.button("Send"):
|
35 |
+
response, metadata, source_documents = chatbot_response(user_input)
|
36 |
+
st.text_area("Chatbot Response:", value=response, height=400)
|
37 |
+
|
38 |
+
st.markdown("### Metadata:")
|
39 |
+
if metadata:
|
40 |
+
for value in metadata:
|
41 |
+
st.write(f"{value}")
|
42 |
+
else:
|
43 |
+
st.write("No metadata available.")
|
44 |
+
|
45 |
+
st.markdown("### Source Documents:")
|
46 |
+
if source_documents:
|
47 |
+
for doc in source_documents:
|
48 |
+
# pass
|
49 |
+
st.write(doc)
|
50 |
+
else:
|
51 |
+
st.write("No source documents found.")
|
52 |
+
|
53 |
+
print_colorful_msg("End Chatbot Response...", color='blue')
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
main()
|