| import pandas as pd |
| import pprint |
| import google.generativeai as palm |
| import pandas as pd |
|
|
| import os |
|
|
| from square.client import Client |
| import gradio as gr |
| import io |
|
|
| from langchain.agents import initialize_agent, AgentType |
| from langchain.llms import GooglePalm |
| import pandas as pd |
| |
| from langchain.chains.question_answering import load_qa_chain |
| from langchain import PromptTemplate, LLMChain |
| from langchain.agents import create_pandas_dataframe_agent |
| from langchain.tools import DuckDuckGoSearchRun |
| from pandasai import PandasAI |
|
|
|
|
| from dotenv import load_dotenv |
|
|
| load_dotenv() |
|
|
|
|
| client = Client( |
| access_token=os.environ['SQUARE_ACCESS_TOKEN'], |
| environment='sandbox') |
|
|
| location_id='LFA70NPRQAEV1' |
|
|
| palm.configure(api_key=os.environ['PALM']) |
|
|
| models = [m for m in palm.list_models( |
| ) if 'generateText' in m.supported_generation_methods] |
| model = models[0].name |
| print(model) |
|
|
|
|
| load_dotenv() |
|
|
|
|
|
|
| |
|
|
| def fetch_inventory_items(): |
| response = client.inventory.batch_retrieve_inventory_counts( |
| body={ |
| 'catalog_object_ids': [], |
| 'location_ids': [] |
| } |
| ) |
| print(response.status_code) |
| print(response.body) |
| inventory_items = response.body['counts'] |
|
|
| items_data = [] |
| for item in inventory_items: |
| item_data = { |
| 'Item Name': item['catalog_object_id'], |
| |
| 'SKU': item['catalog_object_id'], |
| 'Quantity': item['quantity'], |
| 'Location ID': item['location_id'] |
| } |
| items_data.append(item_data) |
|
|
| return items_data |
|
|
|
|
| |
| inventory_items = fetch_inventory_items() |
|
|
| |
| df = pd.DataFrame(inventory_items) |
|
|
|
|
| |
| print(df) |
| df.to_csv("data.csv", index=False) |
| |
| catalog_objects = client.catalog.batch_retrieve_catalog_objects( |
| body={ |
| 'object_ids': df['Item Name'].tolist(), |
| 'include_related_objects': True |
| } |
| ) |
| catalog_objects = catalog_objects.body['objects'] |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
|
|
|
|
|
|
|
|
|
|
| def questiondocument(user_question): |
| load_dotenv() |
| |
| df = pd.read_excel("tour_op.xlsx") |
|
|
| agent = create_pandas_dataframe_agent(GooglePalm(temperature=0, google_api_key=os.environ['PALM']), df, agent="structured_chat-zero-shot-react-description", verbose=True) |
| response = agent.run(user_question) |
| |
|
|
| return response |
|
|
|
|
| demo = gr.Interface( |
|
|
| fn=questiondocument, |
| inputs=["text"], |
| outputs=["text"], |
| title="Ask Busy Helper", |
| ) |
| demo.launch(share=True) |
|
|
|
|