Skip to content

Commit

Permalink
Merge pull request #6 from blue-moon22/mikayel
Browse files Browse the repository at this point in the history
Mikayel
  • Loading branch information
blue-moon22 authored Jun 10, 2023
2 parents da96764 + 3c973bd commit be8db95
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

import time

def addtodatabase(protocol,ingredients):
def addtodatabase(protocol,ingredients,allergen):
#creates and adds to log database to log
#For ! Rating ! Time #

logfile = open('log.txt','a')
currenttime=time.time()
logstring = protocol + "," + ingredients + "," + str(currenttime) + ","
title = "\n" + str(currenttime) + "\n"

logfile.write(title)
logstring = protocol + "," + ingredients + "," + allergen + "," + str(currenttime) + ","
logfile.write(logstring)
logfile.close()

Expand All @@ -30,6 +33,7 @@ def addtodatabaserating(rating):
logfile.write(logstring)
logfile.close()


# App framework
st.title("🪄🧪 FormulAI")
prompt = st.text_input("What would you like to formulate?")
Expand All @@ -50,6 +54,12 @@ def addtodatabaserating(rating):
template = "Write a protocol for putting together the {ingredients} while leveraging this wikipedia reserch:{wikipedia_research}."
)

allergen_template = PromptTemplate(

input_variables = ['ingredients'],
template = "Write a list of potential allergens present in {ingredients}."
)

# Memory
ingredients_memory = ConversationBufferMemory(input_key='chemical', memory_key='chat_history')
protocol_memory = ConversationBufferMemory(input_key='ingredients', memory_key='chat_history')
Expand All @@ -59,6 +69,8 @@ def addtodatabaserating(rating):
llm = OpenAI(model_name="gpt-3.5-turbo")
ingredients_chain = LLMChain(llm=llm, prompt=ingredients_template, verbose=True, output_key="ingredients", memory=ingredients_memory)
protocol_chain = LLMChain(llm=llm, prompt=protocol_template, verbose=True, output_key="protocol", memory=protocol_memory)
allergen_chain = LLMChain(llm=llm, prompt=allergen_template, verbose=True, output_key="allergen", memory=protocol_memory)

csvagent = create_csv_agent(OpenAI(temperature=0.2),'skincare_products_clean.csv',verbose=True, output_key="csvdata", memory=csv_memory)

wiki = WikipediaAPIWrapper()
Expand All @@ -69,13 +81,16 @@ def addtodatabaserating(rating):
ingredients = ingredients_chain.run(chemical=prompt, csvdata=csvdata, selected_option=selected_option)
wiki_research = wiki.run(prompt)
protocol = protocol_chain.run(ingredients=ingredients, wikipedia_research=wiki_research)
allergen = allergen_chain.run(ingredients=ingredients)

st.write('## Ingredients')
st.write(ingredients)
st.write('## Protocol')
st.write(protocol)
st.write(protocol)
st.write('## Allergens')
st.write(allergen)

addtodatabase(protocol,ingredients)
addtodatabase(protocol,ingredients,allergen)

st.write('## Extra Information')
with st.expander('Ingredients History'):
Expand Down

0 comments on commit be8db95

Please sign in to comment.