Mikeplockhart commited on
Commit
7ffc9ec
1 Parent(s): 17fe750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -3,6 +3,11 @@ from langchain_community.document_loaders import JSONLoader
3
  from langchain_community.vectorstores import Qdrant
4
  from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from sentence_transformers.cross_encoder import CrossEncoder
 
 
 
 
 
6
 
7
  # loading data
8
  json_path = "format_food.json"
@@ -64,14 +69,24 @@ def run_query(query):
64
  instructions = format_to_markdown(answer[0].metadata['instructions'])
65
  recipe = f"# Cooking time:\n{answer[0].metadata['time']}\n\n# Recipe:\n{instructions}"
66
  print("Returning query")
67
- return title_and_description, recipe
 
 
 
 
 
 
 
 
 
68
 
69
  with gr.Blocks() as demo:
70
  gr.Markdown("Start typing below and then click **Run** to see the output.")
71
  inp = gr.Textbox(placeholder="What sort of meal are you after?")
72
  title_output = gr.Markdown(label="Title and description")
73
  instructions_output = gr.Markdown(label="Recipe")
 
74
  btn = gr.Button("Run")
75
- btn.click(fn=run_query, inputs=inp, outputs=[title_output, instructions_output])
76
 
77
  demo.launch()
 
3
  from langchain_community.vectorstores import Qdrant
4
  from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from sentence_transformers.cross_encoder import CrossEncoder
6
+ from groq import Groq
7
+
8
+ client = Groq(
9
+ api_key=os.environ.get("GROQ_API"),
10
+ )
11
 
12
  # loading data
13
  json_path = "format_food.json"
 
69
  instructions = format_to_markdown(answer[0].metadata['instructions'])
70
  recipe = f"# Cooking time:\n{answer[0].metadata['time']}\n\n# Recipe:\n{instructions}"
71
  print("Returning query")
72
+ chat_completion = client.chat.completions.create(
73
+ messages=[
74
+ {
75
+ "role": "user",
76
+ "content": f"please write a more detailed recipe for the following recipe:\n{recipe}\n\n please return it in the same format.",
77
+ }
78
+ ],
79
+ model="Llama3-70b-8192",
80
+ )
81
+ return title_and_description, recipe, chat_completion[0].text
82
 
83
  with gr.Blocks() as demo:
84
  gr.Markdown("Start typing below and then click **Run** to see the output.")
85
  inp = gr.Textbox(placeholder="What sort of meal are you after?")
86
  title_output = gr.Markdown(label="Title and description")
87
  instructions_output = gr.Markdown(label="Recipe")
88
+ updated_recipe = gr.Markdown(label="Updated Recipe")
89
  btn = gr.Button("Run")
90
+ btn.click(fn=run_query, inputs=inp, outputs=[title_output, instructions_output, updated_recipe])
91
 
92
  demo.launch()