karthickg12 commited on
Commit
b64d695
1 Parent(s): 39e0066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -40
app.py CHANGED
@@ -27,44 +27,65 @@
27
  # chat()
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  import streamlit as st
31
- from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
32
-
33
- # Load BlenderBot model and tokenizer
34
- model_name = "facebook/blenderbot-400M-distill"
35
- tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
36
- model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
37
-
38
- # Function to generate a response from BlenderBot
39
- def get_blenderbot_response(input_text):
40
- inputs = tokenizer(input_text, return_tensors="pt")
41
- reply_ids = model.generate(**inputs)
42
- response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
43
- return response
44
-
45
- # Streamlit app
46
- st.title("Insurance Q&A Chatbot")
47
- st.write("Ask any question about insurance, and I'll do my best to help!")
48
-
49
- # Chat history
50
- if "history" not in st.session_state:
51
- st.session_state.history = []
52
-
53
- # Input text box for user
54
- user_input = st.text_input("You:", "")
55
-
56
- # Respond to user input
57
- if user_input:
58
- # Add user question to history
59
- st.session_state.history.append({"user": user_input})
60
-
61
- # Generate bot response
62
- response = get_blenderbot_response(user_input)
63
- st.session_state.history.append({"bot": response})
64
-
65
- # Display chat history
66
- for message in st.session_state.history:
67
- if "user" in message:
68
- st.write("**You:**", message["user"])
69
- if "bot" in message:
70
- st.write("**Bot:**", message["bot"])
 
27
  # chat()
28
 
29
 
30
+ # import streamlit as st
31
+ # from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
32
+
33
+ # # Load BlenderBot model and tokenizer
34
+ # model_name = "facebook/blenderbot-400M-distill"
35
+ # tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
36
+ # model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
37
+
38
+ # # Function to generate a response from BlenderBot
39
+ # def get_blenderbot_response(input_text):
40
+ # inputs = tokenizer(input_text, return_tensors="pt")
41
+ # reply_ids = model.generate(**inputs)
42
+ # response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
43
+ # return response
44
+
45
+ # # Streamlit app
46
+ # st.title("Insurance Q&A Chatbot")
47
+ # st.write("Ask any question about insurance, and I'll do my best to help!")
48
+
49
+ # # Chat history
50
+ # if "history" not in st.session_state:
51
+ # st.session_state.history = []
52
+
53
+ # # Input text box for user
54
+ # user_input = st.text_input("You:", "")
55
+
56
+ # # Respond to user input
57
+ # if user_input:
58
+ # # Add user question to history
59
+ # st.session_state.history.append({"user": user_input})
60
+
61
+ # # Generate bot response
62
+ # response = get_blenderbot_response(user_input)
63
+ # st.session_state.history.append({"bot": response})
64
+
65
+ # # Display chat history
66
+ # for message in st.session_state.history:
67
+ # if "user" in message:
68
+ # st.write("**You:**", message["user"])
69
+ # if "bot" in message:
70
+ # st.write("**Bot:**", message["bot"])
71
+
72
  import streamlit as st
73
+ from rasa.core.agent import Agent
74
+ from rasa.shared.core.domain import Domain
75
+ from rasa.shared.core.tracker_store import InMemoryTrackerStore
76
+ from rasa.shared.nlu.interpreter import RasaNLUInterpreter
77
+
78
+ # Load Rasa model
79
+ domain = Domain.load("insurance_domain.yml")
80
+ interpreter = RasaNLUInterpreter("insurance_nlu.pkl")
81
+ tracker_store = InMemoryTrackerStore(domain)
82
+ agent = Agent.load("insurance_model", interpreter=interpreter, tracker_store=tracker_store)
83
+
84
+ # Define Streamlit app
85
+ st.title("Insurance Chatbot")
86
+
87
+ user_input = st.text_area("You:", height=200)
88
+
89
+ if st.button("Send"):
90
+ response = agent.handle_text(user_input)
91
+ st.text_area("Bot:", value=response[0].text, height=200, max_chars=None, key=None)