pratikshahp commited on
Commit
84be3f5
·
verified ·
1 Parent(s): 7014ab2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -11,8 +11,13 @@ load_dotenv()
11
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
13
  # Function to process the image and get response from Gemini model
14
- def get_gemini_response(input_prompt, uploaded_file_path, query):
15
  try:
 
 
 
 
 
16
  # Validate the image file path
17
  if not uploaded_file_path or not os.path.exists(uploaded_file_path):
18
  return "Please upload a valid image."
@@ -32,11 +37,6 @@ def get_gemini_response(input_prompt, uploaded_file_path, query):
32
  except Exception as e:
33
  return f"Error: {e}"
34
 
35
- # Define input prompt
36
- default_prompt = """
37
- You are an expert in understanding invoices. You will receive input images as invoices and
38
- you will have to answer questions based on the input image.
39
- """
40
 
41
  # Define Gradio interface
42
  with gr.Blocks() as invoice_extractor:
@@ -47,9 +47,6 @@ with gr.Blocks() as invoice_extractor:
47
  The system uses Google's Gemini model to extract and interpret the invoice details.
48
  """
49
  )
50
-
51
- input_prompt = default_prompt
52
- # gr.Textbox(label="Input Prompt", value=default_prompt, lines=2)
53
  image_input = gr.Image(label="Upload Invoice Image", type="filepath") # Use type="filepath"
54
  query_input = gr.Textbox(label="Enter your query about the invoice", placeholder="e.g., What is the total amount?")
55
  output_response = gr.Textbox(label="Response", lines=5)
@@ -60,7 +57,7 @@ with gr.Blocks() as invoice_extractor:
60
  # Set the button to call the processing function
61
  submit_btn.click(
62
  get_gemini_response,
63
- inputs=[input_prompt, image_input, query_input],
64
  outputs=output_response
65
  )
66
 
 
11
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
13
  # Function to process the image and get response from Gemini model
14
+ def get_gemini_response(uploaded_file_path, query):
15
  try:
16
+ # Define input prompt
17
+ input_prompt = """
18
+ You are an expert in understanding invoices. You will receive input images as invoices and
19
+ you will have to answer questions based on the input image.
20
+ """
21
  # Validate the image file path
22
  if not uploaded_file_path or not os.path.exists(uploaded_file_path):
23
  return "Please upload a valid image."
 
37
  except Exception as e:
38
  return f"Error: {e}"
39
 
 
 
 
 
 
40
 
41
  # Define Gradio interface
42
  with gr.Blocks() as invoice_extractor:
 
47
  The system uses Google's Gemini model to extract and interpret the invoice details.
48
  """
49
  )
 
 
 
50
  image_input = gr.Image(label="Upload Invoice Image", type="filepath") # Use type="filepath"
51
  query_input = gr.Textbox(label="Enter your query about the invoice", placeholder="e.g., What is the total amount?")
52
  output_response = gr.Textbox(label="Response", lines=5)
 
57
  # Set the button to call the processing function
58
  submit_btn.click(
59
  get_gemini_response,
60
+ inputs=[image_input, query_input],
61
  outputs=output_response
62
  )
63