Spaces:
Build error
Build error
Update app.py
Browse files134 unmodified lines13513613713813814013914014114214514314414814914514614786 unmodified lines23423523624224323724524623823924024124225225325425524324425825924524624724824926525025126826925225325410 unmodified lines26526626728628728828929029129229329429529629729829930030130230330430530630730830931031131226831431531631731831926927027132027232227332427427527633 unmodified lines310311312364365313367314369315316317165 unmodified lines4834844855414864874884893 unmodified lines4934944955515524964974984991 unmodified line5015025035605615625635045055065071 unmodified line5095105115715125135145155165765175185195202 unmodified lines52352452558558652652752858952953053153253353459553559753653753853911 unmodified lines55155255361555455555690 unmodified lines647648649712650651652653134 unmodified lines# The function that uses the above models# Define the function that will handle the database querydef database_tool(question): # print(question) sql_query = generate_sql_query(question) #print(sql_query) return run_query(sql_query)
def get_ASN_data(question): # print(question) base_url = os.getenv("ASN_API_URL") complete_url = f"{base_url}branchMaster.id=343&transactionUid={question}&userId=164&transactionType=ASN" #print("complete url") #print(complete_url) try: response = requests.get(complete_url) data = response.json()86 unmodified lines print(f"Document data tool enter: {question}") # query_string = question['tags'][0] if 'tags' in question and question['tags'] else "" query_response = query_vector_store(vector_store, question, config={"callbacks": [langfuse_handler]}) #print("query****") #print(query_response) # summarized_response = summarize_document(query_response) # print("summary***") # print(summarized_response) return query_response
def send_email_with_attachment(recipient_email, subject, body, image_data): try: print(recipient_email) print(subject) #print(image_data) sender_email = os.getenv("EMAIL_SENDER") sender_password = os.getenv("EMAIL_PASSWORD") print(sender_email) print(sender_password) # Create a multipart message msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = recipient_email msg['Subject'] = subject print(body) # Attach the body with the msg instance msg.attach(MIMEText(body, 'plain')) print(body) """ # Open the file to be sent attachment = open(attachment_path, "rb") #print("Attached the image")10 unmodified lines # Attach the instance 'part' to instance 'msg' msg.attach(part) # Create a MIMEBase instance for the attachment part = MIMEBase('application', 'octet-stream') # Set the payload with the image data part.set_payload(image_data) # Encode the payload into base64 encoders.encode_base64(part) # Add a header with the filename (you can set any filename you prefer) part.add_header('Content-Disposition', 'attachment; filename="image.png"') # Attach the instance 'part' to the instance 'msg' msg.attach(part)""" # Create SMTP session for sending the mail print(body) context = ssl.create_default_context() with smtplib.SMTP("smtp.gmail.com", 587) as server: server.ehlo() # Can be omitted server.starttls(context=context) server.ehlo() # Can be omitted server.login(sender_email, sender_password) text = msg.as_string() server.sendmail(sender_email, recipient_email, text)
with smtplib.SMTP_SSL('smtp.gmail.com', 25) as smtp_server: smtp_server.login(sender, password) #server = smtplib.SMTP('smtp.gmail.com', 587) #server.starttls() #server.login(sender_email, sender_password) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(sender_email, sender_password) print(body) text = msg.as_string() print(body) server.sendmail(sender_email, recipient_email, text) print(body) server.quit() except Exception as error:33 unmodified lines else: return "warehouse name not found"
#print(apis[0]["url"]) #print(apis[0]["params"]) data = make_api_request(apis[0]["url"], apis[0]["params"]) #print(warehouse_name) if data: #print(data) # Extracting the id for the warehouse with the name "WH" warehouse_id = next((item['id'] for item in data['result'] if item['name'] == warehouse_name), None) #print(warehouse_id)165 unmodified lines user_question = "Could not request results from Google Speech Recognition service."
while iterations < max_iterations: #print(user_question) """if "send email to" in user_question: email_match = re.search(r"send email to ([\w\.-]+@[\w\.-]+)", user_question) if email_match:3 unmodified lines """
response = agent_executor.invoke({"input": user_question}, config={"callbacks": [langfuse_handler]}) #print("name") #print(warehouse_name) if isinstance(response, dict): response_text = response.get("output", "") else:1 unmodified line if "invalid" not in response_text.lower(): break iterations += 1 #print(os.getenv("IMAGE_PATH")) #print(response_text) #print("validating. ") #print(os.getenv("IMAGE_PATH") in response_text) if iterations == max_iterations: return "The agent could not generate a valid response within the iteration limit."
1 unmodified line if os.getenv("IMAGE_PATH") in response_text: # Open the image file img = Image.open(os.getenv("IMAGE_PATH")) #print(img) # Convert the PIL Image to a base64 encoded string buffered = BytesIO() img.save(buffered, format="PNG") img_str = base64.b64encode(buffered.getvalue()).decode("utf-8") #print(img_str) img = f'<img src="data:image/png;base64,{img_str}" style="width:500px; height:400px;">' # image = gr.Image(value=img_str) chatbot.append((user_question, img))2 unmodified lines match = re.search(email_pattern, user_question) if match: user_email = match.group() # Return the matched email #print("user_email") #print(user_email) # email send if len(user_email)>0: print("user_email") # Send email with the chart image attached send_email_with_attachment( recipient_email=user_email, subject="Warehouse Inventory Report", body=response.get("output", "").split(":")[0], image_data = img_str # attachment_path=chart_path #attachment_path=os.getenv("IMAGE_PATH") attachment_path=os.getenv("IMAGE_PATH") )
if "send email to" in user_question:11 unmodified lines # return "/home/user/app/exports/charts/temp_chart.png" else: chatbot.append((user_question, response_text)) # print(chatbot) return gr.update(value=chatbot) # response_text = response_text.replace('\n', ' ').replace(' ', ' ').strip() # return response_text90 unmodified lines return gr.update(visible=False), gr.update(visible=False)
with gr.Blocks(css=css,theme=gr.themes.Soft()) as demo:with gr.Blocks(css=css) as demo: gr.Markdown("<CENTER><h2 style='font-size: 20px; font-family: Calibri;'>NewageNXT GPT</h2></CENTER>") with gr.Row(): sample_button = gr.Button("What are the details of ASN24080600008", elem_classes="custom-button" , elem_id="button1")app.py+12-74