exponeto / demo.py
rairo's picture
Upload folder using huggingface_hub
d38bbd7
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 yolopandas import 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()
# Define a function to fetch inventory items
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 not available in response, using catalog_object_id as a placeholder
'SKU': item['catalog_object_id'],
'Quantity': item['quantity'],
'Location ID': item['location_id']
}
items_data.append(item_data)
return items_data
# Fetch inventory items
inventory_items = fetch_inventory_items()
# Convert inventory data to a Pandas dataframe
df = pd.DataFrame(inventory_items)
# Print the dataframe
print(df)
df.to_csv("data.csv", index=False)
# Retrieve catalog objects
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']
#print(catalog_objects)
#llm = GooglePalm(google_api_key=os.environ['PALM'])
#llm.temperature = 0.1
#prompts = ['Explain the difference between effective and affective with examples']
#llm_result = llm._generate(prompts)
#print(llm_result.generations[0][0].text)
def questiondocument(user_question):
load_dotenv()
#df = pd.read_csv("data.csv")
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)
#response = pandas_ai(df, prompt=user_question)
return response
demo = gr.Interface(
fn=questiondocument,
inputs=["text"],
outputs=["text"],
title="Ask Busy Helper",
)
demo.launch(share=True)