mobius.dev commited on
Commit
bba9878
Β·
1 Parent(s): 1938657

change code structure

Browse files

streamlit dont rerun so i place all script in one

contents/dataset/fishfry-locations.csv ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ venue_name,venue_type,venue_address,website,menu_url,menu_text,phone,email,alcohol,lunch
2
+ McGinnis Sisters,Market,"4311 Northern Pike, Monroeville, PA",http://www.mcginnis-sisters.com/,,,412-858-7000,,,True
3
+ Holy Cross (Reilly Center),Church,"7100 West Ridge Road, Fairview PA",,,"Fried pollack, fried shrimp, or combo. Adult $10, Child $5. Includes baked potato, homemade coleslaw, roll, butter, dessert, and beverage. Mac and cheese $5. ",814-474-2605,,,
4
+ Hartford Heights Volunteer Fire Department,Fire Department,"14335 U.S. 30, Irwin, PA 15642",https://www.facebook.com/HHVFD/,https://www.facebook.com/photo.php?fbid=1885613354784664&set=gm.2086300038274058&type=3&theater,,412-824-9972,,True,False
5
+ Beaver Valley Yacht Club,Community Organization,"219 Front Street, New Brighton, Pennsylvania 15066, United States",https://www.beavervalleyyachtclub.org/,,"Menu & Cost:
6
+ Eat in or take out. Adult Fish Dinner (Cod or Perch) $9, Adult Shrimp Dinner $9.25, Adult Chicken Tenders Dinner $8.50, Fish Sandwich (Cod or Perch) $7.25-Senior (60+) and Child pricing available. Dinners incl. 3 sides & roll -- Sandwich incl. 1 side. Sides: Cole Slaw, French Fries, Mac & Cheese. All incl. sales tax and coffee or hot tea. **Cash Only** Cash bar available.
7
+ ",(724) 847-4663,,True,True
8
+ "Our Lady of Joy, Holiday Park",Church,"2000 O'Block Road Holiday Park, PA",http://www.ourladyofjoy.org,,"Menu is a la carte, and features fried or baked fish, cole slaw, grilled cheese, haluski, macaroni and cheese, french fries, soft drinks, coffee and variety of desserts. Sandwiches are $7. Free ice cream for children. ",412-795-3388,,,
9
+ St Alphonsus Wheeling And St John Benwood Combined Fish Fry,Church,"2111 Market St, Wheeling, WV",https://www.facebook.com/StAlphonsusWheelingWV/,,"Menu consists of fish sandwiches, french fries, macaroni and cheese, cabbage and noodles, cole slaw, deserts, and refreshments. Eat in or take out.",304-905-6589 takeout,,,True
10
+ St. Mary of the Mount Church - Sullivan Hall,Church,"131 Bigham, Pittsburgh, PA",http://www.smomp.org,,"Menu features fried and baked fish dinners, shrimp dinner, homemade pierogies, macaroni and cheese, cole slaw, soups and dessert. Costs: $10 adults; $9 seniors; $5 child; $8 sandwich. ",412-390-4011,,,False
11
+ Ancient Order of Hibernians,Community Organization,"302 Mansfield Avenue Carnegie, Pa. 15106",http://www.aohdivision32.org/,,"Great fish, haluska, Mac and cheese, shrimp....reasonable prices and alcohol if desired.
12
+ ",xxx-xxx-xxxx,aohdiv32@gmail.com,True,False
13
+ Bridgeville Volunteer Fire Department,Fire Department,"370 Commercial Street, Bridgeville, PA",http://www.bridgevillevfd.com/2017fishfrymenu.pdf,,see website link,xxx-xxx-xxxx,,False,False
14
+ Christ the Light of the World,Church,"32 S 1st St, Duquesne, PA 15110",https://www.christthelightoftheworld.org/,,"Cod Fish Sandwich, Jumbo Shrimp, Mac & Cheese, Waffle Fries, Haluski, Potato Pancakes, Cole Slaw and Home Made Desserts.",412-466-8960,,False,True
15
+ Bobtown and Dunkard Twp Volunteer Fire (ADDRESS UNCERTAIN),Fire Department,"1 Larimer Ave Bobtown, Pa 15315",https://www.facebook.com/Bobtown-Dunkard-Township-Vol-Fire-Dept-186206404761913/,https://www.facebook.com/186206404761913/photos/a.638412672874615.1073741829.186206404761913/1556094534439753/?type=3&theater,see website link for full menu,724-839-7140,,False,True
16
+ Tower Restaurant,Restaurant,"680 W Chestnut St Washington, PA 15301",,,,724-222-5952,,,True
17
+ Manor Volunteer Fire Department,Fire Department,"40 Main Street, Manor, Pennsylvania 15665, United States",http://manorvfd.org/,,"Dinners:
18
+ 1 Piece Fish Dinner - $8
19
+ 2 Piece Fish Dinner - $10
20
+ 6 Piece Shrimp Dinner - $9
21
+ 9 Piece Shrimp Dinner - $11
22
+ 4 Piece Chicken Dinner - $10
23
+ Dinners Include: 2 Sides, Dinner Roll, Butter, Beverage and Dessert
24
+ Platter:
25
+ Fish Sandwich Platter - $10
26
+ Platter Includes: 2 Pieces of Fish in a Big Bun, 1 Side, Beverage and Dessert
27
+ Kids Meal:
28
+ Kids Meal - $5
29
+ Kids Meal Includes: A choice of a Hotdog, Hamburger, Cheeseburger, Chicken (2 Pieces)
30
+ Or Fish (1 Piece), Plus 1 Side, a Beverage and Dessert
31
+ Al a Carte:
32
+ 1 Piece of Fish - $3
33
+ 3 Pieces of Shrimp - $2
34
+ 2 Pieces of Chicken - $2
35
+ Sides -$1
36
+ Fish Sandwich - $6
37
+ Beverage - $1
38
+ Dessert - $2
39
+ ",(724) 863-5610,,,False
40
+ "St. Peter, Northside",Church,"907 Middle St, Pittsburgh, PA 15212",http://www.stpeterparish.org,http://www.stpeterparish.org/,"Menu: baked or fried cod; salmon; crab cakes; macaroni and cheese or cabbage and noodles, stewed tomatoes or vegetable of the day; french fries; cole slaw or pickled beets. Also, roll and butter, coffee or tea. Cost is $10 for dinner, $6 for sandwiches. ",412-321-2499,,False,False
41
+ "St. Patrick, Canonsburg",Church," 317 W Pike St, Canonsburg, PA 15317",www.stpatrickparish.net,,"Lunch menu features hand-breaded cod sandwich in adult and child size, soup and sides. Delivery is available for lunch within seven miles with minimum order of $30. Dinner entrees include hand-breaded baked or fried cod, shrimp and seafood platter, with two sides, roll and butter, dessert and beverage. Sides include hush puppies, haluski, macaroni and cheese, cole slaw, applesauce and stewed tomatoes. Also featuring homemade desserts. Homemade pierogies for sale, cooked with butter and onions, or dozen frozen.",724-745-6560,,,True
42
+ All Saints,Church,"11264 Route 97 North, Waterford PA",,,"Baked or fried white fish. Adult $9, Child 12 and under $4, Toddlers free. Includes choice of baked potato and french fries, coleslaw/applesauce, homemade desserts, and drink.",814-796-3023,,,False
43
+ Doublewide Grill (Mars/Cranberry),Resturant,"100 Adams Shoppes, Cranberry, PA",,,,xxx-xxx-xxxx,,,
44
+ "St. Malachy, Kennedy Township",Church,"343 Forest Grove Road Kennedy Township, PA",www.stmalachypgh.org,http://www.stmalachypgh.org/FISH%20FRY%202018%20MENU.pdf,"Menu features 1-pound fish sandwich, baked fish, tuna salad sandwich, crab cake sandwich, shrimp, pierogies, macaroni and cheese, cabbage and noodles, cole slaw, french fries. ",412-771-0848,,False,True
45
+ Hogfathers Washington Crown Center,Restaurant,"1500 West Chestnut Street, Washington, PA 15301",hogfathersbbq.com,,,724-222-9227,,True,True
46
+ "Our Lady of the Valley, Donora",Church,"1 Park Manor Rd. Donora, PA",,,"Dinner entrees: baked or fried ""monster"" fish; breaded jumbo shrimp; crab cakes. Dinners are $12.75, and include entree, choice of french fries or pierogies, cole slaw, dessert and beverage (for dine-in customers). Also, ""monster"" baked or fried fish sandwich, with cole slaw is $9.75, and shrimp in a basket (five) with cole slaw is $9.75. A la carte menu includes french fries, pierogies, pasta fagioli with bread, cole slaw, dessert, buns and beverages. ",724-379-7559,,False,True
47
+ Centerville American Legion Post 705,Community Organization,1101 Old National Pike Fredericktown PA 15333,https://www.facebook.com/CALPost705/,https://www.facebook.com/CALPost705/photos/a.578206219030287.1073741828.334499336734311/602404116610497/?type=3&theater,,724-632-9591,,,False
48
+ Pizzarita,Restaurant,"580 Burchfield Rd., Allison Park, PA",http://pizzaritapgh.com/,,,,,,True
49
+ St Gregory Russian Orthodox Church,Church,"214 E. 15th Ave, Homestead, PA 15120",http://www.stgregoryrussianchurch.org/,http://www.stgregoryrussianchurch.org/fish-fry-english/,,412-462-8256,,False,True
50
+ Coy's Store & Pizza Shop,Unsure / N/A,"11919 U.S. 422 Penn Run, PA 15765",http://coyspizza.com/,http://coyspizza.com/our-menu/,,724-463-9449,,,True
51
+ Riley's Pour House,Restaurant,"215 East Main Street, Carnegie, Pennsylvania 15106, United States",http://www.rileyspourhouse.com/,,,412.279.0770,,True,True
52
+ Fairmont-Hahntown VFD,Fire Department,"890 Rose St, Irwin, PA 15642",,,,xxx-xxx-xxxx,,,
53
+ Larimer VFD,Fire Department,"1340 Brownstown Rd., Larimer, PA",,,,xxx-xxx-xxxx,,,
54
+ St. Agnes/Holy Trinity,Church,"Holy Trinity Church Social Hall, 529 Grant Avenue Ext West Mifflin, PA 15122-3830",stagneswm.com,,"Fried and baked fish dinners and sandwiches, shrimp and crab cake dinners; pierogies; haluski; homemade soups of the day.",Takeout available; call 412-466-9695.,,False,True
55
+ Holy Spirit (West Mifflin),Church,"2603 Old Elizabeth Road, West Mifflin, Pa 15122",https://facebook.com/holyspiritchurch/,,,412-346-0477,19201@diopitt.org,,
56
+ "Our Lady of the Miraculous Medal, Meadow Lands",Church,"300 Pike St, Meadow Lands, PA",http://miraculousmedalchurch.org/,http://miraculousmedalchurch.org/CCD-Events-Hall/Fish-Fry,"Menu features Panko breaded cod, deep-fried in heart healthy tri-fry oil that is cholesterol- and trans fat-free. Other healthier options include baked cod or salmon, Maine lobster rolls and tuna melts. Also featuring homemade crab cakes, jumbo shrimp, and cabbage and noodles. Back by popular demand is seafood pizza. Side orders include green beans, baked potatoes, french fries, cole slaw, and macaroni and cheese. Featuring breads from Breadworks and homemade desserts.",724-228-8575,,,True
57
+ "St. Therese of Lisieux, Munhall",Church,"3 Saint Therese Court, Homestead, Pennsylvania 15120, United States",http://www.st-therese.net/,,"Menu includes fried and baked fish, shrimp, homemade crab cakes, soup and more.",412-462-8164,,,False
58
+ Hanover Volunteer Fire Department Fish Fry,Fire Department,"9 Starck Drive, Burgettstown, PA 15021",hanovervfd45.com,,"Fish Dinner with Cole Slaw and One Side - $12.00
59
+ Shrimp Dinner with Cole Slaw and One Side - $12.00
60
+ Fish Sandwich - $10.00
61
+ Shrimp Basket - $10.00
62
+ Chicken Sandwich - $5.00
63
+ Mac and Cheese - $3.00
64
+ Haluski - $3.00
65
+ French Fries - $3.00
66
+ Pierogies (4) - $3.00
67
+ Cole Slaw - $3.00
68
+ Drinks - $1.00",724-729-3929,,False,True
69
+ "St Elizabeth Ann Seton, Carnegie",Church,"330 3rd Ave, Carnegie, PA 15106",,,"Dinner menu: fish trio (fried fish, shrimp, crab cake), baked or fried fish, jumbo shrimp, crab cakes (served with fries, cole slaw, roll and butter); macaroni and cheese with stewed tomatoes; pierogies (served with cole slaw, roll and butter); fish Parmesan (served with pasta marinara, and roll and butter). A la carte menu: baked and fried fish sandwich, crab cakes, popcorn shrimp, pierogies, french fries, pasta marinara, haluski, macaroni and cheese, stewed tomatoes, applesauce, cole slaw, clam chowder, potato soup. Also featuring homemade desserts and other treats. ",412-276-1011 ext 220,,,True
70
+ Geeseytown Community Fire Company,Fire Department,"215 Mary Street, Hollidaysburg, Pennsylvania 16648, United States",https://www.facebook.com/Geeseytown-Community-Fire-Company-1531587100412091/,,,(814) 695-8003,,,False
71
+ "ASH WEDNESDAY AND GOOD FRIDAY ONLY Prince of Peace, South Side ",Church,"81 S. 13th St. Pittsburgh, PA",http://www.princeofpeacepittsburgh.org/,,"Menu: fish (baked or fried) or crab cake, with applesauce or cole slaw, two sides, dessert, coffee or tea, $9; fish (baked or fried) or crab cake sandwich, with applesauce or cole slaw, $6. Pierogies are three for $2.50, or $7 per dozen (frozen). ",412-481-8380,,,
72
+ "Transfiguration/St. Victor, Bairdford",Church,"527 Bairdford Road Bairdford, PA",http://www.stvictors.org/,https://uploads.weconnect.com/mce/a4c36ded9dbf60a5a9dceb0d0a1e3b17ac92f8cf/2017%20FF%20Menu.pdf,,724-265-4017,,,True
73
+ Connellsville Twp. VFD,Fire Department,"905 Fireman Street, Connellsville, Pennsylvania 15425, United States",,https://www.facebook.com/564084873610128/photos/a.666221240063157.1073741827.564084873610128/1799858140032789/?type=3&theater,,724-628-0900,,,True
74
+ Assumption,Church,"45 North Sprague Avenue, Bellevue, PA 15202",https://www.assumptionchurch.org/,,"Menu features hand-breaded fish and cole slaw made from scratch. Traditional Eastern European sides offered, with homemade desserts available. Also, low-carb dinner available. Cost is $11 for adults, $3 for child and $8 for sandwich, with various a la carte items sold. ",412-766-9727,,False,False
75
+ "St. Fidelis, Butler",Church,"125 Buttercup Road, Butler, Pennsylvania 16001, United States",,,"Dinner menu, choice of deep-fried or baked fish, scalloped potatoes or french fries, green beans, cole slaw, bread and butter, beverage and dessert. Cost: $10 adults, $5 children age 10 and under, free for child under 2. All takeout is $10. ",,,,False
76
+ Penn Hills Bar and Grill,Restaurant,"11507 Frankstown Road, Pittsburgh, Pennsylvania 15235, United States",,,,(412) 241-2218,,,
77
+ Rene's,Restaurant,"1030 Fifth Avenue East McKeesport, PA",http://www.renesrestaurant.net/,,"Full Lenten menu, including 1-lb fish sandwich",412-823-9544,,True,True
78
+ Hills Restaurant,Restaurant,"107 Main St, New Eagle, PA 15067",https://www.facebook.com/Hills-Restaurant-117576318259711/,,,724-258-5422,,,True
79
+ St. Luke,Church,421 East 38th Street. Erie PA,http://www.slserie.org/,,Fish Dinner - 10. Captains Platter - 12 Shrimp Basket - 7,814-825-7105,,False,False
80
+ Hookstown Volunteer Fire Department,Fire Department,"102 Silver Slipper Rd Hookstown, Pennsylvania",,,,xxx-xxx-xxxx,,,
81
+ St. Philip- Ascension Worship Site,Church,"114 Berry St., Pittsburgh, PA",,,fish sandwich; fish sandwich dinner; baked fish dinner; jumbo shrimp dinner; homemade crab cake dinner; seafood dinner; macaroni and cheese; green beans; grilled cheese; salad; soup; haluski; desserts; beverages.,,,,False
82
+ Most Holy Name,Church,"1515 Tinsbury Street, Pittsburgh, PA",https://www.mostholynameofjesusparish15212.org/,,"Dinner menu, $10: fried or baked cod; crab cakes (two); breaded jumbo shrimp (six). Dinners come with choice of two sides (french fries, homemade macaroni and cheese, homemade cole slaw, applesauce, stewed tomatoes), homemade dessert, beverage (for dine-in only). A la carte menu and takeout available",,,,False
83
+ Adamsburg VFD,Fire Department,"495 Edna Rd, Adamsburg, Pennsylvania 15611",https://www.facebook.com/AdamsburgVfd,,See their Facebook page (https://www.facebook.com/AdamsburgVfd) for the complete menu.,724-527-2180,,False,True
84
+ St. Mary Orthodox Church,Church,"105 S. 19th St. Pittsburgh, PA 15203",http://www.stmaryorthodoxchurch.net/,,"Fish Sandwich - $6.00
85
+ Choice of fries, cole slaw, or applesauce
86
+ Shrimp - $7.00
87
+ Choice of fries, cole slaw, or applesauce
88
+ Baked Fish - $6.00
89
+ Greek Salad - $5.00
90
+ Crab Cake - $5.00
91
+ 3 Pierogi - $3.00
92
+ Halushki - $3.00
93
+ Mac & Cheese - $3.00
94
+ Pop or Water - $1.00
95
+ Various deserts
96
+ ",412-431-6428,,False,True
97
+ S&D Polish Deli,Restaurant,"2204 Penn Avenue, Pittsburgh, Pennsylvania 15222, United States",http://sdpolishdeli.com/sdpolishdeli/,https://www.facebook.com/sdpolishdelipittsburgh/photos/rpp.544254162312994/1801789979892733/?type=3&theater,"All platters come with coleslaw and haluszki or 3 pierogi or mac 'n cheese
98
+ Baked Fish Platter - $12
99
+ Fried Fish Platter - $12
100
+ Meatless Stuffed Cabbage Platter - $12
101
+ Potato Pancake Platter - $12
102
+
103
+ A la carte
104
+ Fried Fish Sandwich - $8
105
+ Mushroom Stuffed Cabbage - $4
106
+ 4 Pierogi - $5
107
+ 12 Pierogi - $11
108
+ Haluszki - $6 Large, $3 Small
109
+ Mac 'n Cheese - $5 Large, $3 Small
110
+ 2 Potato Pancakes - $5
111
+ Coleslaw - $5 large, $3 small
112
+ Soup of the Day - $4
113
+ Dessert of the Day - $5
114
+ ",412-281-2906,,False,True
dataset/2018pittsburghfishfrylocations.csv DELETED
The diff for this file is too large to render. See raw diff
 
dataset/fishfry-locations.csv DELETED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -1,7 +1,7 @@
1
- langchain
2
- streamlit
3
- pandas
4
  streamlit_chat
 
 
5
  openai
6
  chromadb
7
  tiktoken
 
1
+ streamlit==1.21.0
 
 
2
  streamlit_chat
3
+ pandas==1.5.3
4
+ langchain==0.0.133
5
  openai
6
  chromadb
7
  tiktoken
src/app.py DELETED
@@ -1,23 +0,0 @@
1
- import streamlit as st
2
- from chat_csv import chat_csv
3
-
4
- # streamlit run src/app.py
5
-
6
- # Configure the Streamlit page
7
- st.set_page_config(layout="wide", page_icon="contents\logo_site.png", page_title="Talk-Sheet")
8
-
9
- # Render the main header
10
- st.markdown(
11
- "<h1 style='text-align: center;'>Talk-Sheet, Talk with your sheet-data ! πŸ’¬</h1>",
12
- unsafe_allow_html=True
13
- )
14
-
15
- # Input field for the user's OpenAI API key
16
- user_secret = st.sidebar.text_input(
17
- label="#### Your OpenAI API key πŸ‘‡",
18
- placeholder="Paste your openAI API key, sk-",
19
- type="password",
20
- )
21
-
22
- # Call the main function with the provided API key
23
- chat_csv(user_secret)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/chat_csv.py DELETED
@@ -1,142 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import os
4
-
5
- from pathlib import Path
6
-
7
- from streamlit_chat import message
8
-
9
- from langchain.chat_models import ChatOpenAI
10
- from langchain.vectorstores import Chroma
11
- from langchain.prompts import PromptTemplate
12
- from langchain.document_loaders.csv_loader import CSVLoader
13
- from langchain.text_splitter import CharacterTextSplitter
14
- from langchain.embeddings.openai import OpenAIEmbeddings
15
- from langchain.chains import RetrievalQA
16
-
17
- def chat_csv(user_secret):
18
- os.environ["OPENAI_API_KEY"] = user_secret
19
- try:
20
- if user_secret == "":
21
- st.markdown(
22
- "<div style='text-align: center;'><h4>Enter your OpenAI API key to start chatting πŸ˜‰</h4></div>",
23
- unsafe_allow_html=True
24
- )
25
- else:
26
- # Upload CSV file
27
- uploaded_file = st.sidebar.file_uploader("", type=["csv"])
28
- if uploaded_file is not None:
29
- # Show uploaded CSV file
30
- def show_user_file():
31
- file_container = st.expander("Votre fichier CSV :")
32
- shows = pd.read_csv(uploaded_file)
33
- uploaded_file.seek(0)
34
- file_container.write(shows)
35
-
36
- show_user_file()
37
-
38
- else :
39
- st.sidebar.info(
40
-
41
- "πŸ‘† Upload a .csv file to get started, "
42
- "example : [fishfry-locations.csv](https://drive.google.com/file/d/1l9WZo6TBleAWMdkxAAmM5fRHIU3fBpGW/view?usp=sharing)"
43
- )
44
-
45
- if uploaded_file:
46
- # Save user's CSV file
47
- def save_user_file(uploaded_file):
48
- save_folder = 'dataset'
49
- save_path = Path(save_folder, uploaded_file.name)
50
- with open(save_path, mode='wb') as w:
51
- w.write(uploaded_file.getvalue())
52
-
53
- file_path_user=os.path.join('dataset/', uploaded_file.name)
54
- return file_path_user
55
-
56
- # Create retriever from user's CSV file
57
- def formalize_user_file_for_llm(file_path_user):
58
- loader = CSVLoader(file_path=file_path_user, encoding="utf-8")
59
- data = loader.load()
60
- text_splitter = CharacterTextSplitter(chunk_size=1500, chunk_overlap=0)
61
- texts = text_splitter.split_documents(data)
62
-
63
- embeddings = OpenAIEmbeddings()
64
-
65
- db = Chroma.from_documents(texts, embeddings)
66
- retriever = db.as_retriever()
67
- return retriever
68
-
69
- user_file_path = save_user_file(uploaded_file)
70
- retriever_db = formalize_user_file_for_llm(user_file_path)
71
-
72
- # Create custom prompt for MonAmiPoto
73
- def adapt_llm_response_to_prompt():
74
- prompt_template = (
75
- "You are Talk-Sheet, a user-friendly chatbot designed to assist users by engaging in conversations based on data from CSV or Excel files. "
76
- "Your knowledge comes from:"
77
-
78
- " {context} "
79
-
80
- "Help users by providing relevant information from the data in their files. Answer their questions accurately and concisely. "
81
- "If the user's specific issue or need cannot be addressed with the available data, "
82
- "empathize with their situation and suggest that they may need to seek assistance elsewhere. "
83
- "Always maintain a friendly and helpful tone. "
84
- "If you don't know the answer to a question, truthfully say you don't know."
85
-
86
- "Human: {question} "
87
-
88
- "Talk-Sheet: "
89
- )
90
-
91
-
92
- PROMPT = PromptTemplate(template=prompt_template, input_variables=["context","question"])
93
- chain_type_kwargs = {"prompt": PROMPT}
94
- return chain_type_kwargs
95
-
96
- custom_pompt = adapt_llm_response_to_prompt()
97
-
98
- # Initialize RetrievalQA with custom prompt and retriever
99
- qa = RetrievalQA.from_chain_type(llm =ChatOpenAI(temperature=0, model="gpt-3.5-turbo"), chain_type='stuff', retriever=retriever_db, chain_type_kwargs=custom_pompt)
100
-
101
- # Chatbot UI function
102
- def chatbot_ui(qa):
103
- if 'generated' not in st.session_state:
104
- st.session_state['generated'] = []
105
-
106
- if 'past' not in st.session_state:
107
- st.session_state['past'] = []
108
-
109
- def generate_response(query):
110
- response = qa.run(query)
111
- print(f"Type of response: {type(response)}, response: {response}")
112
-
113
- return response
114
-
115
- def get_text():
116
- st.write("")
117
- input_text = st.text_input("##### Demandez de l'aide Γ  Poto Γ  partir de votre base de donnΓ©es πŸ‘‡: ", key="input")
118
- return input_text
119
- user_input = get_text()
120
-
121
- if user_input:
122
- output = generate_response(user_input)
123
-
124
- st.session_state.past.append(user_input)
125
- st.session_state.generated.append(output)
126
-
127
- if st.session_state['generated']:
128
- print(f"st.session_state['generated']: {st.session_state['generated']}")
129
-
130
- for i in range(len(st.session_state['generated'])-1, -1, -1):
131
- message(st.session_state["generated"][i], key=str(i))
132
- message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
133
- chatbot_ui(qa)
134
-
135
- except Exception as e:
136
- st.error(f"Error: {str(e)}")
137
-
138
- # About section
139
- st.sidebar.title("About Talk-Sheet πŸ€–")
140
- st.sidebar.subheader("Talk-Sheet is a user-friendly chatbot designed to assist users by engaging in conversations based on data from CSV or excel files. πŸ“„")
141
- st.sidebar.subheader("Ideal for various purposes and users, Talk-Sheet provides a simple yet effective way to interact with your sheet-data. 🌐")
142
- st.sidebar.subheader("Powered by ChatGPT API, Langchain, and OpenAI, Talk-Sheet offers a seamless and personalized experience. ⚑")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
talk_sheet.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+
5
+ from pathlib import Path
6
+
7
+ from streamlit_chat import message
8
+
9
+ from langchain.chat_models import ChatOpenAI
10
+ from langchain.vectorstores import Chroma
11
+ from langchain.prompts import PromptTemplate
12
+ from langchain.document_loaders.csv_loader import CSVLoader
13
+ from langchain.text_splitter import CharacterTextSplitter
14
+ from langchain.embeddings.openai import OpenAIEmbeddings
15
+ from langchain.chains import RetrievalQA
16
+ from langchain.memory import ChatMessageHistory
17
+ from langchain.callbacks import get_openai_callback
18
+ import tiktoken
19
+
20
+ # Configure the Streamlit page
21
+ st.set_page_config(layout="wide", page_icon="contents\logo_site.png", page_title="Talk-Sheet")
22
+
23
+ st.markdown(
24
+ "<h1 style='text-align: center;'>Talk-Sheet, Talk with your sheet-data ! πŸ’¬</h1>",
25
+ unsafe_allow_html=True
26
+ )
27
+
28
+ # Input field for the user's OpenAI API key
29
+ user_secret = st.sidebar.text_input(
30
+ label="#### Your OpenAI API key πŸ‘‡",
31
+ placeholder="Paste your openAI API key, sk-",
32
+ type="password",
33
+ )
34
+ os.environ["OPENAI_API_KEY"] = user_secret
35
+
36
+
37
+ if user_secret == "":
38
+ st.markdown(
39
+ "<div style='text-align: center;'><h4>Enter your OpenAI API key to start chatting πŸ˜‰</h4></div>",
40
+ unsafe_allow_html=True
41
+ )
42
+ else:
43
+ # Upload CSV file
44
+ uploaded_file = st.sidebar.file_uploader(".", type=["csv"])
45
+ if uploaded_file is not None:
46
+ # Show uploaded CSV file
47
+ def show_user_file(uploaded_file):
48
+ file_container = st.expander("Votre fichier CSV :")
49
+ shows = pd.read_csv(uploaded_file)
50
+ uploaded_file.seek(0)
51
+ file_container.write(shows)
52
+
53
+ show_user_file(uploaded_file)
54
+
55
+ else :
56
+ st.sidebar.info(
57
+
58
+ "πŸ‘† Upload a .csv file to get started, "
59
+ "example : [fishfry-locations.csv](https://drive.google.com/file/d/18i7tN2CqrmoouaSqm3hDfAk17hmWx94e/view?usp=sharing)"
60
+ )
61
+
62
+ if uploaded_file:
63
+
64
+ # Save user's CSV file
65
+ def save_user_file(uploaded_file):
66
+ save_folder = 'contents\dataset'
67
+ save_path = Path(save_folder, uploaded_file.name)
68
+ with open(save_path, mode='wb') as w:
69
+ w.write(uploaded_file.getvalue())
70
+
71
+ file_path_user=os.path.join('contents\dataset', uploaded_file.name)
72
+ return file_path_user
73
+ user_file_path = save_user_file(uploaded_file)
74
+
75
+ # Create custom prompt for CSV chatbot
76
+ def adapt_llm_response_to_prompt():
77
+ prompt_template = (
78
+ "You are Talk-Sheet, a user-friendly chatbot designed to assist users by engaging in conversations based on data from CSV or Excel files. "
79
+ "Your knowledge comes from:"
80
+
81
+ " {context} "
82
+
83
+ "Help users by providing relevant information from the data in their files. Answer their questions accurately and concisely. "
84
+ "If the user's specific issue or need cannot be addressed with the available data, "
85
+ "empathize with their situation and suggest that they may need to seek assistance elsewhere. "
86
+ "Always maintain a friendly and helpful tone. "
87
+ "If you don't know the answer to a question, truthfully say you don't know."
88
+
89
+ "Human: {question} "
90
+
91
+ "Talk-Sheet: "
92
+ )
93
+
94
+ PROMPT = PromptTemplate(template=prompt_template, input_variables=["context","question"])
95
+ chain_type_kwargs = {"prompt": PROMPT}
96
+ return chain_type_kwargs
97
+
98
+ custom_pompt = adapt_llm_response_to_prompt()
99
+
100
+ try:
101
+ # Create retriever from user's CSV file
102
+ def formalize_user_file_for_llm(file_path_user):
103
+ loader = CSVLoader(file_path=file_path_user, encoding="utf-8")
104
+ data = loader.load()
105
+ text_splitter = CharacterTextSplitter(chunk_size=1500, chunk_overlap=0)
106
+ texts = text_splitter.split_documents(data)
107
+
108
+ embeddings = OpenAIEmbeddings()
109
+
110
+ db = Chroma.from_documents(texts, embeddings)
111
+ retriever = db.as_retriever()
112
+ return retriever
113
+
114
+ retriever_db = formalize_user_file_for_llm(user_file_path)
115
+
116
+ # Initialize RetrievalQA with custom prompt and retriever
117
+ qa = RetrievalQA.from_chain_type(llm =ChatOpenAI(temperature=0, model="gpt-3.5-turbo"), chain_type='stuff', retriever=retriever_db, chain_type_kwargs=custom_pompt)
118
+
119
+
120
+
121
+ def count_tokens(chain, query):
122
+ with get_openai_callback() as cb:
123
+ result = chain.run(query)
124
+ print(f'Spent a total of {cb.total_tokens} tokens')
125
+
126
+ return result
127
+ # Chatbot UI function
128
+ def chatbot_ui(qa):
129
+ if 'generated' not in st.session_state:
130
+ st.session_state['generated'] = []
131
+
132
+ if 'past' not in st.session_state:
133
+ st.session_state['past'] = []
134
+
135
+ def generate_response(query):
136
+ response = qa.run(query)
137
+ print(f"Type of response: {type(response)}, response: {response}")
138
+ return response
139
+
140
+ def get_text():
141
+ input_text = st.text_input("##### Let's Talk ! πŸ‘‡: ", key="input")
142
+ return input_text
143
+
144
+ user_input = get_text()
145
+
146
+ if user_input:
147
+ output = generate_response(user_input)
148
+
149
+ st.session_state.past.append(user_input)
150
+ st.session_state.generated.append(output)
151
+
152
+ if st.session_state['generated']:
153
+ print(f"st.session_state['generated']: {st.session_state['generated']}")
154
+
155
+ for i in range(len(st.session_state['generated'])-1, -1, -1):
156
+ message(st.session_state["generated"][i], key=str(i))
157
+ message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
158
+
159
+ chatbot_ui(qa)
160
+ except Exception as e:
161
+ st.error(f"Error: {str(e)}")
162
+
163
+
164
+
165
+ # About section
166
+ st.sidebar.title("About Talk-Sheet πŸ€–")
167
+ st.sidebar.subheader("Talk-Sheet is a user-friendly chatbot designed to assist users by engaging in conversations based on data from CSV or excel files. πŸ“„")
168
+ st.sidebar.subheader("Ideal for various purposes and users, Talk-Sheet provides a simple yet effective way to interact with your sheet-data. 🌐")
169
+ st.sidebar.subheader("Powered by ChatGPT API, Langchain, and OpenAI, Talk-Sheet offers a seamless and personalized experience. ⚑")