Skip to content

Commit

Permalink
tutorial91
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Jun 22, 2024
1 parent 35ee69a commit bf0e02c
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 0 deletions.
Binary file added tutorial91/__pycache__/fetch_price.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added tutorial91/__pycache__/table_gen.cpython-311.pyc
Binary file not shown.
103 changes: 103 additions & 0 deletions tutorial91/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
product,unit,price
Apple,1 kg,6.42
Banana,1 kg,1.79
Orange,1 packet,18.62
Milk,1 kg,5.65
Bread,1 packet,16.7
Eggs,1 kg,19.33
Butter,1 packet,10.09
Cheese,1 packet,14.16
Chicken Breast,1 packet,15.4
Beef,1 kg,2.59
Pork,1 packet,1.6
Fish,1 kg,6.66
Shrimp,1 kg,3.79
Rice,1 litre,10.0
Pasta,1 litre,13.67
Olive Oil,1 packet,12.61
Salt,1 kg,16.92
Pepper,1 kg,16.87
Tomato,1 Kg,12.04
Potato,1 Kg,3.41
Onion,1 kg,19.3
Garlic,1 kg,18.32
Broccoli,1 kg,19.64
Carrot,1 litre,11.52
Cucumber,1 packet,17.82
Lettuce,1 litre,3.99
Spinach,1 kg,18.13
Mushroom,1 kg,3.75
Bell Pepper,1 packet,6.36
Zucchini,1 packet,3.79
Cabbage,1 litre,16.54
Cauliflower,1 kg,7.77
Corn,1 packet,2.29
Peas,1 litre,10.24
Green Beans,1 kg,3.61
Lemon,1 packet,15.15
Lime,1 packet,15.99
Strawberry,1 litre,19.39
Blueberry,1 packet,4.67
Raspberry,1 litre,8.51
Blackberry,1 packet,17.04
Pineapple,1 kg,16.57
Mango,1 kg,18.49
Papaya,1 litre,15.9
Watermelon,1 litre,3.78
Grapes,1 litre,14.63
Kiwi,1 packet,14.3
Cherry,1 litre,16.13
Peach,1 kg,11.07
Plum,1 litre,12.41
Apricot,1 kg,10.84
Nectarine,1 kg,3.18
Coconut,1 kg,13.74
Almonds,1 packet,10.66
Walnuts,1 litre,6.21
Cashews,1 litre,7.51
Pistachios,1 kg,4.54
Peanut Butter,1 packet,18.73
Jelly,1 packet,3.81
Honey,1 litre,13.9
Oatmeal,1 packet,11.32
Cereal,1 packet,13.3
Flour,1 packet,17.51
Sugar,1 litre,12.64
Baking Powder,1 packet,3.36
Baking Soda,1 kg,19.97
Vinegar,1 kg,9.81
Soy Sauce,1 litre,11.94
Ketchup,1 kg,6.17
Mustard,1 kg,19.09
Mayonnaise,1 packet,16.34
Hot Sauce,1 litre,2.83
Pickles,1 packet,3.93
Jam,1 packet,9.99
Yogurt,1 kg,11.68
Ice Cream,1 litre,14.79
Frozen Peas,1 kg,18.26
Frozen Corn,1 litre,7.35
Frozen Spinach,1 kg,16.85
Frozen Pizza,1 packet,8.75
Chicken Nuggets,1 packet,16.49
Hot Dogs,1 kg,8.07
Bacon,1 kg,1.36
Sausage,1 kg,5.2
Salami,1 packet,11.68
Ham,1 litre,16.85
Turkey,1 litre,11.85
Beef Jerky,1 kg,12.97
Granola Bars,1 litre,6.31
Chips,1 kg,4.99
Pretzels,1 kg,5.8
Popcorn,1 packet,5.96
Chocolate,1 packet,9.84
Cookies,1 litre,15.44
Cake Mix,1 litre,13.8
Brownie Mix,1 packet,16.21
Pancake Mix,1 kg,2.58
Syrup,1 kg,5.47
Tea,1 kg,17.75
Coffee,1 kg,6.8
Juice,1 packet,19.67
Soda,1 litre,13.3
9 changes: 9 additions & 0 deletions tutorial91/fetch_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pandas as pd
df=pd.read_csv(r"C:\Users\welcome\OneDrive\Documents\GitHub\LLMtutorial\tutorial91\data.csv")
df["price"]=pd.to_numeric(df["price"],errors="coerce")

def getPrice(name,unit):
dfp=df[df["product"].str.lower()==name.lower()]
price=dfp["price"].values[0]*float(unit)
return price

33 changes: 33 additions & 0 deletions tutorial91/genrate_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from reportlab.lib import colors

# Create a PDF document
pdf_file = "invoice.pdf"
document = SimpleDocTemplate(pdf_file, pagesize=letter)

# Sample data for the table
def gentable(data):

# Create a table
table = Table(data)

# Add style to the table
style = TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, 0), 12),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black)
])

table.setStyle(style)

# Build the PDF
elements = [table]
document.build(elements)

print(f"PDF with table created: {pdf_file}")
Binary file added tutorial91/invoice.pdf
Binary file not shown.
65 changes: 65 additions & 0 deletions tutorial91/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import json,base64
import streamlit as st
from fetch_price import getPrice
from genrate_table import gentable


llm=ChatOpenAI(model="gpt-4o",temperature=0)
prompt="""
you are an intelligent bot who can translate any {instruction} into a json document with the following keys:
product_name
quantity_volume
output will be only json nothing else
"""

def show_pdf(file_path):
with open(file_path,"rb") as f1:
base64_pdf=base64.b64encode(f1.read()).decode("utf-8")
pdf_display=f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1200" height="900" type="application/pdf"></iframe>'
st.markdown(pdf_display,unsafe_allow_html=True)

def genresponse(input):
query_with_prompt=PromptTemplate(
template=prompt,
input_variables=["instruction"]
)
llmchain=LLMChain(llm=llm,prompt=query_with_prompt)
response=llmchain.invoke({"instruction":input})
data=response["text"]
data=data.replace("json","")
data=data.replace("`","")
data=json.loads(data)
return data

st.title("INVOICE GENERATOR APP")
st.write("what you want to order")
input=st.text_area("write your requirements")
if input is not None:
btn=st.button("submit")
if btn:
response=genresponse(input)
if isinstance(response,dict):
name=response["product_name"]
unit=response["quantity_volume"][0]
price=getPrice(name,unit)
response["price"]=price
if isinstance(response,list):
for item in response:
name=item["product_name"]
unit=item["quantity_volume"][0]
price=getPrice(name,unit)
item["price"]=price
final_data=[["NAME","QUANTITY_VOLUME","PRICE"]]
for data in response:
product_lists=[data["product_name"],data["quantity_volume"],data["price"]]
final_data.append(product_lists)
st.write(final_data)
gentable(final_data)
file_path=r"C:\Users\welcome\OneDrive\Documents\GitHub\LLMtutorial\tutorial91\invoice.pdf"
show_pdf(file_path)


Binary file added tutorial91/tutorial91.pptx
Binary file not shown.

0 comments on commit bf0e02c

Please sign in to comment.