Nechama commited on
Commit
87eac61
·
verified ·
1 Parent(s): 3841128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -4,11 +4,11 @@ from transformers import pipeline, AutoModelForVision2Seq, AutoProcessor
4
  import torch
5
 
6
  # Load the OpenGVLab/InternVL-Chat-V1-5 model and processor
7
- processor = AutoProcessor.from_pretrained("OpenGVLab/InternVL-Chat-V1-5")
8
- model = AutoModelForVision2Seq.from_pretrained("OpenGVLab/InternVL-Chat-V1-5")
9
 
10
  # Load the Llama3 model for text processing
11
- llama_model = pipeline("text2text-generation", model="llama3")
12
 
13
  def process_image(image):
14
  # Process the image to extract the recipe using OpenGVLab
@@ -18,25 +18,17 @@ def process_image(image):
18
 
19
  return extracted_text
20
 
21
- def adjust_recipe(extracted_text, adjustment):
22
- # Create the prompt for Llama3 to adjust the recipe
23
- prompt = f"Here is a recipe: {extracted_text}. Please {adjustment} the recipe."
24
- response = llama_model(prompt)
25
- return response[0]['generated_text']
26
-
27
- def app(image, adjustment):
28
- extracted_text = process_image(image)
29
- adjusted_recipe = adjust_recipe(extracted_text, adjustment)
30
- return adjusted_recipe
31
-
32
- # Create the Gradio interface
33
- interface = gr.Interface(
34
- fn=app,
35
- inputs=[gr.inputs.Image(type="file"), gr.inputs.Dropdown(["double", "halve"])],
36
  outputs="text",
37
- title="Recipe Adjuster",
38
- description="Upload an image of a recipe, and this app will double or halve the recipe."
39
  )
40
 
 
41
  if __name__ == "__main__":
42
- interface.launch()
 
4
  import torch
5
 
6
  # Load the OpenGVLab/InternVL-Chat-V1-5 model and processor
7
+ from transformers import AutoModel
8
+ model = AutoModel.from_pretrained("OpenGVLab/InternVL-Chat-V1-5", trust_remote_code=True)
9
 
10
  # Load the Llama3 model for text processing
11
+ #llama_model = pipeline("text2text-generation", model="llama3")
12
 
13
  def process_image(image):
14
  # Process the image to extract the recipe using OpenGVLab
 
18
 
19
  return extracted_text
20
 
21
+ iface = gr.Interface(
22
+ fn=process_image,
23
+ inputs=[
24
+ gr.components.Image(type="filepath", label="Recipe Image"),
25
+ #gr.components.Radio(choices=["Double", "Triple", "Half", "Third"], label="Action")
26
+ ],
 
 
 
 
 
 
 
 
 
27
  outputs="text",
28
+ title="Recipe Modifier",
29
+ description="Upload an image of a recipe and choose how to modify the measurements.",
30
  )
31
 
32
+
33
  if __name__ == "__main__":
34
+ interface.launch(share=True)