Spaces:
Runtime error
Runtime error
Srinivasulu kethanaboina
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ 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 |
import random
|
8 |
import datetime
|
9 |
import uuid
|
@@ -92,6 +93,26 @@ def save_chat_history(history):
|
|
92 |
json.dump(history, f)
|
93 |
print(f"Chat history saved as {chat_history_path}")
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Define the function to handle predictions
|
96 |
def predict(message, history):
|
97 |
logo_html = '''
|
@@ -107,7 +128,7 @@ def predict(message, history):
|
|
107 |
|
108 |
return response_with_logo
|
109 |
|
110 |
-
# Define your Gradio chat interface function
|
111 |
def chat_interface(message, history):
|
112 |
try:
|
113 |
# Process the user message and generate a response
|
@@ -151,8 +172,14 @@ div.svelte-rk35yg {display: none;}
|
|
151 |
div.progress-text.svelte-z7cif2.meta-text {display: none;}
|
152 |
'''
|
153 |
|
154 |
-
gr.ChatInterface(chat_interface,
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
import uuid
|
|
|
93 |
json.dump(history, f)
|
94 |
print(f"Chat history saved as {chat_history_path}")
|
95 |
|
96 |
+
# Save to Salesforce
|
97 |
+
save_to_salesforce(current_chat_history)
|
98 |
+
|
99 |
+
def save_to_salesforce(history):
|
100 |
+
username =os.getenv("username")
|
101 |
+
password =os.getenv("password")
|
102 |
+
security_token =os.getenv("security_token")
|
103 |
+
domain = 'test'
|
104 |
+
|
105 |
+
session_id, sf_instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
|
106 |
+
sf = Salesforce(instance=sf_instance, session_id=session_id)
|
107 |
+
for past_query, response in history:
|
108 |
+
data = {
|
109 |
+
'Name': 'Chat with user',
|
110 |
+
'Bot_Message__c': response,
|
111 |
+
'User_Message__c': past_query,
|
112 |
+
'Date__c': str(datetime.datetime.now().date())
|
113 |
+
}
|
114 |
+
sf.Chat_History__c.create(data)
|
115 |
+
|
116 |
# Define the function to handle predictions
|
117 |
def predict(message, history):
|
118 |
logo_html = '''
|
|
|
128 |
|
129 |
return response_with_logo
|
130 |
|
131 |
+
# Define your Gradio chat interface function
|
132 |
def chat_interface(message, history):
|
133 |
try:
|
134 |
# Process the user message and generate a response
|
|
|
172 |
div.progress-text.svelte-z7cif2.meta-text {display: none;}
|
173 |
'''
|
174 |
|
175 |
+
demo = gr.ChatInterface(chat_interface,
|
176 |
+
css=css,
|
177 |
+
description="Lily",
|
178 |
+
clear_btn=None, undo_btn=None, retry_btn=None,
|
179 |
+
)
|
180 |
+
|
181 |
+
# Add a button to save chat history
|
182 |
+
gr.Button("Close Chat").click(fn=save_chat_history)
|
183 |
+
|
184 |
+
# Launch the interface
|
185 |
+
demo.launch()
|