Spaces:
Runtime error
Runtime error
HabibaMoataz
commited on
Commit
•
dfdccdc
1
Parent(s):
5669567
Upload 2 files
Browse files- app.py +54 -0
- requirements.txt +9 -0
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
3 |
+
from langchain_openai import ChatOpenAI
|
4 |
+
from langchain.chains import RetrievalQA
|
5 |
+
from langchain.vectorstores import FAISS
|
6 |
+
|
7 |
+
|
8 |
+
def recipe_generator(ingredients):
|
9 |
+
"""
|
10 |
+
This function takes a list of ingredients as input and returns a recipe using the LangChain library and OpenAI API.
|
11 |
+
"""
|
12 |
+
# Load the LangChain model and vector store
|
13 |
+
embedd = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large")
|
14 |
+
vector_store = FAISS.load_local("faiss_index", embedd,allow_dangerous_deserialization=True)
|
15 |
+
|
16 |
+
# Create the LangChain chain
|
17 |
+
llm = ChatOpenAI(
|
18 |
+
openai_api_key="sk-proj-JjAAcDuAsxPkm3zg9Iz2T3BlbkFJ5txMWIx2TS6T24rPYhjN",
|
19 |
+
model="gpt-3.5-turbo",
|
20 |
+
temperature=0.3
|
21 |
+
)
|
22 |
+
qa_chain = RetrievalQA.from_chain_type(
|
23 |
+
llm,
|
24 |
+
retriever=vector_store.as_retriever(),
|
25 |
+
return_source_documents=True
|
26 |
+
)
|
27 |
+
|
28 |
+
# Generate the recipe
|
29 |
+
question = f"Make a recipe using the following ingredients: {ingredients}"
|
30 |
+
result = qa_chain({"query": question})
|
31 |
+
return result["result"]
|
32 |
+
|
33 |
+
# Create the Gradio interface
|
34 |
+
interface = gr.Interface(
|
35 |
+
fn=recipe_generator,
|
36 |
+
inputs=[
|
37 |
+
gr.Textbox(
|
38 |
+
show_label=False,
|
39 |
+
placeholder="Enter your ingredients separated by commas"
|
40 |
+
),
|
41 |
+
],
|
42 |
+
outputs=[
|
43 |
+
"textbox",
|
44 |
+
],
|
45 |
+
examples=[
|
46 |
+
["chicken, rice, vegetables"],
|
47 |
+
["pasta, tomato sauce, cheese"],
|
48 |
+
],
|
49 |
+
title="Recipe Generator",
|
50 |
+
description="Enter a list of ingredients and I will generate a recipe for you."
|
51 |
+
)
|
52 |
+
|
53 |
+
# Launch the Gradio app
|
54 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
faiss-cpu
|
2 |
+
langchain-community
|
3 |
+
sentence-transformers
|
4 |
+
tiktoken
|
5 |
+
openai
|
6 |
+
langchain-openai
|
7 |
+
langchain_community
|
8 |
+
langchain_openai
|
9 |
+
langchain
|