Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -29,14 +29,7 @@ llm_client = InferenceClient(
|
|
29 |
)
|
30 |
|
31 |
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
|
32 |
-
username = os.getenv("username")
|
33 |
-
password = os.getenv("password")
|
34 |
-
security_token = os.getenv("security_token")
|
35 |
-
domain = os.getenv("domain")# Using sandbox environment
|
36 |
-
session_id, sf_instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
|
37 |
|
38 |
-
# Create Salesforce object
|
39 |
-
sf = Salesforce(instance=sf_instance, session_id=session_id)
|
40 |
|
41 |
app = FastAPI()
|
42 |
|
@@ -153,10 +146,7 @@ def handle_query(query):
|
|
153 |
response ="Sorry, I couldn't find an answer."
|
154 |
current_chat_history.append((query, response))
|
155 |
return response
|
156 |
-
|
157 |
-
async def load_chat(request: Request, id: str):
|
158 |
-
return templates.TemplateResponse("index.html", {"request": request, "user_id": id})
|
159 |
-
# Route to save chat history
|
160 |
@app.post("/hist/")
|
161 |
async def save_chat_history(history: dict):
|
162 |
# Check if 'userId' is present in the incoming dictionary
|
@@ -181,28 +171,7 @@ async def save_chat_history(history: dict):
|
|
181 |
return {"error": f"Failed to update lead: {str(e)}"}, 500
|
182 |
|
183 |
return {"summary": result, "message": "Chat history saved"}
|
184 |
-
|
185 |
-
async def receive_form_data(request: Request):
|
186 |
-
form_data = await request.json()
|
187 |
-
# Log in to Salesforce
|
188 |
-
first_name, last_name = split_name(form_data['name'])
|
189 |
-
data = {
|
190 |
-
'FirstName': first_name,
|
191 |
-
'LastName': last_name,
|
192 |
-
'Description': 'hii', # Static description
|
193 |
-
'Company': form_data['company'], # Assuming company is available in form_data
|
194 |
-
'Phone': form_data['phone'].strip(), # Phone from form data
|
195 |
-
'Email': form_data['email'], # Email from form data
|
196 |
-
}
|
197 |
-
a=sf.Lead.create(data)
|
198 |
-
# Generate a unique ID (for tracking user)
|
199 |
-
unique_id = a['id']
|
200 |
-
|
201 |
-
# Here you can do something with form_data like saving it to a database
|
202 |
-
print("Received form data:", form_data)
|
203 |
-
|
204 |
-
# Send back the unique id to the frontend
|
205 |
-
return JSONResponse({"id": unique_id})
|
206 |
|
207 |
@app.post("/chat/")
|
208 |
async def chat(request: MessageRequest):
|
@@ -216,6 +185,7 @@ async def chat(request: MessageRequest):
|
|
216 |
}
|
217 |
chat_history.append(message_data)
|
218 |
return {"response": response}
|
219 |
-
@app.get("/")
|
220 |
-
def
|
221 |
-
return {"
|
|
|
|
29 |
)
|
30 |
|
31 |
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
32 |
|
|
|
|
|
33 |
|
34 |
app = FastAPI()
|
35 |
|
|
|
146 |
response ="Sorry, I couldn't find an answer."
|
147 |
current_chat_history.append((query, response))
|
148 |
return response
|
149 |
+
|
|
|
|
|
|
|
150 |
@app.post("/hist/")
|
151 |
async def save_chat_history(history: dict):
|
152 |
# Check if 'userId' is present in the incoming dictionary
|
|
|
171 |
return {"error": f"Failed to update lead: {str(e)}"}, 500
|
172 |
|
173 |
return {"summary": result, "message": "Chat history saved"}
|
174 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
@app.post("/chat/")
|
177 |
async def chat(request: MessageRequest):
|
|
|
185 |
}
|
186 |
chat_history.append(message_data)
|
187 |
return {"response": response}
|
188 |
+
@app.get("/", response_class=HTMLResponse)
|
189 |
+
async def load_chat(request: Request, id: str):
|
190 |
+
return templates.TemplateResponse("index.html", {"request": request, "user_id": id})
|
191 |
+
# Route to save chat history
|