shukdevdatta123 commited on
Commit
5cb63f8
·
verified ·
1 Parent(s): 8d0cf2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -24,7 +24,7 @@ def generate_response(prompt, openai_api_key, image_info="", reasoning_effort="m
24
  {"role": "system", "content": "You are a helpful assistant."},
25
  {"role": "user", "content": full_prompt},
26
  ],
27
- max_completion_tokens=2000, # Use max_completion_tokens instead of max_tokens
28
  reasoning_effort=reasoning_effort # Include reasoning_effort in the request
29
  )
30
  return response["choices"][0]["message"]["content"]
@@ -43,11 +43,11 @@ def get_base64_string_from_image(pil_image):
43
  def chatbot(input_text, image, openai_api_key, reasoning_effort, history=[]):
44
  image_info = ""
45
 
46
- # If an image is uploaded, convert it to base64 for reference
47
  if image:
48
  try:
49
  image = Image.open(image)
50
- image_info = get_base64_string_from_image(image)
51
  except Exception as e:
52
  image_info = f"Error reading image: {e}"
53
 
@@ -72,7 +72,7 @@ def create_interface():
72
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
73
 
74
  with gr.Row():
75
- image_input = gr.Image(label="Upload an Image", type="pil")
76
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
77
 
78
  with gr.Row():
 
24
  {"role": "system", "content": "You are a helpful assistant."},
25
  {"role": "user", "content": full_prompt},
26
  ],
27
+ max_completion_tokens=300, # Use max_completion_tokens instead of max_tokens
28
  reasoning_effort=reasoning_effort # Include reasoning_effort in the request
29
  )
30
  return response["choices"][0]["message"]["content"]
 
43
  def chatbot(input_text, image, openai_api_key, reasoning_effort, history=[]):
44
  image_info = ""
45
 
46
+ # If an image is uploaded, convert it to base64 for reference (this does NOT analyze the image directly)
47
  if image:
48
  try:
49
  image = Image.open(image)
50
+ image_info = get_base64_string_from_image(image) # Store base64 string for the image
51
  except Exception as e:
52
  image_info = f"Error reading image: {e}"
53
 
 
72
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
73
 
74
  with gr.Row():
75
+ image_input = gr.Image(label="Upload an Image", type="pil") # Image upload input
76
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
77
 
78
  with gr.Row():