Srinivasulu kethanaboina commited on
Commit
e40503c
1 Parent(s): 110c6a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -43
app.py CHANGED
@@ -4,7 +4,6 @@ from dotenv import load_dotenv
4
  from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate, Settings
5
  from llama_index.llms.huggingface import HuggingFaceInferenceAPI
6
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
- from simple_salesforce import Salesforce, SalesforceLogin
8
  import random
9
  import datetime
10
 
@@ -48,7 +47,7 @@ def handle_query(query):
48
  (
49
  "user",
50
  """
51
- You are the Lily Redfernstech chatbot. Your goal is to provide accurate, professional, and helpful answers to user queries based on the company's data. Always ensure your responses are clear and concise. give response within 10-15 words only
52
  {context_str}
53
  Question:
54
  {query_str}
@@ -83,42 +82,6 @@ def handle_query(query):
83
 
84
  return response
85
 
86
- def save_chat_history_to_salesforce():
87
- username =os.getenv("username")
88
- password =os.getenv("password")
89
- security_token =os.getenv("security_token")
90
- domain = 'test'
91
-
92
- # Log in to Salesforce
93
- session_id, sf_instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
94
-
95
- # Create Salesforce object
96
- sf = Salesforce(instance=sf_instance, session_id=session_id)
97
-
98
- # Iterate over chat history dictionary and push to Salesforce
99
- for chat_id, (user_message, bot_response) in current_chat_history.items():
100
- data = {
101
- 'Name': 'Chat with user',
102
- 'Bot_Message__c': bot_response,
103
- 'User_Message__c': user_message,
104
- 'Date__c': str(datetime.datetime.now().date())
105
- }
106
- # Insert into the custom object (replace 'Chat_History__c' with your custom object's API name)
107
- sf.Chat_History__c.create(data)
108
-
109
- # Define the function to handle predictions
110
- def predict(message, history):
111
- logo_html = '''
112
- <div class="circle-logo">
113
- <img src="https://rb.gy/8r06eg" alt="FernAi">
114
- </div>
115
- '''
116
- response = handle_query(message)
117
- response_with_logo = f'<div class="response-with-logo">{logo_html}<div class="response-text">{response}</div></div>'
118
-
119
- # Return the response with the logo
120
- return response_with_logo
121
-
122
  # Define your Gradio chat interface function
123
  def chat_interface(message, history):
124
  try:
@@ -163,11 +126,8 @@ div.progress-text.svelte-z7cif2.meta-text {display: none;}
163
 
164
  # Use Gradio Blocks to wrap components
165
  with gr.Blocks() as demo:
166
- chat = gr.ChatInterface(chat_interface, css=css, description="Lily", clear_btn=None, undo_btn=None, retry_btn=None)
167
-
168
- # Add a button to save chat history
169
- save_button = gr.Button("Save History")
170
- save_button.click(fn=save_chat_history_to_salesforce)
171
 
172
  # Launch the Gradio interface
173
  demo.launch()
 
4
  from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate, Settings
5
  from llama_index.llms.huggingface import HuggingFaceInferenceAPI
6
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
 
7
  import random
8
  import datetime
9
 
 
47
  (
48
  "user",
49
  """
50
+ You are the Lily Redfernstech chatbot. Your goal is to provide accurate, professional, and helpful answers to user queries based on the company's data. Always ensure your responses are clear and concise. Give response within 10-15 words only
51
  {context_str}
52
  Question:
53
  {query_str}
 
82
 
83
  return response
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Define your Gradio chat interface function
86
  def chat_interface(message, history):
87
  try:
 
126
 
127
  # Use Gradio Blocks to wrap components
128
  with gr.Blocks() as demo:
129
+ # Add the chat interface only
130
+ chat = gr.ChatInterface(chat_interface, css=css, clear_btn=None, undo_btn=None, retry_btn=None)
 
 
 
131
 
132
  # Launch the Gradio interface
133
  demo.launch()