Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from langchain_community.embeddings import HuggingFaceEmbeddings | |
| from langchain_openai import ChatOpenAI | |
| from langchain.chains import RetrievalQA | |
| from langchain.vectorstores import FAISS | |
| def recipe_generator(ingredients): | |
| """ | |
| This function takes a list of ingredients as input and returns a recipe using the LangChain library and OpenAI API. | |
| """ | |
| # Load the LangChain model and vector store | |
| embedd = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large") | |
| vector_store = FAISS.load_local("faiss_index", embedd,allow_dangerous_deserialization=True) | |
| # Create the LangChain chain | |
| llm = ChatOpenAI( | |
| openai_api_key="sk-proj-JjAAcDuAsxPkm3zg9Iz2T3BlbkFJ5txMWIx2TS6T24rPYhjN", | |
| model="gpt-3.5-turbo", | |
| temperature=0.3 | |
| ) | |
| qa_chain = RetrievalQA.from_chain_type( | |
| llm, | |
| retriever=vector_store.as_retriever(), | |
| return_source_documents=True | |
| ) | |
| # Generate the recipe | |
| question = f"Make a recipe using the following ingredients: {ingredients}" | |
| result = qa_chain({"query": question}) | |
| return result["result"] | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=recipe_generator, | |
| inputs=[ | |
| gr.Textbox( | |
| show_label=False, | |
| placeholder="Enter your ingredients separated by commas" | |
| ), | |
| ], | |
| outputs=[ | |
| "textbox", | |
| ], | |
| examples=[ | |
| ["chicken, rice, vegetables"], | |
| ["pasta, tomato sauce, cheese"], | |
| ], | |
| title="Recipe Generator", | |
| description="Enter a list of ingredients and I will generate a recipe for you." | |
| ) | |
| # Launch the Gradio app | |
| interface.launch() | |