Spaces:
Runtime error
Runtime error
Update app.py
Browse files3 unmodified lines4567891 unmodified line11121314151649 unmodified lines666768697071727374757677787980813 unmodified linesimport tempfileimport osimport openaiprompt = "Type and press Enter"1 unmodified linewith open(image_path, "rb") as image_file:return base64.b64encode(image_file.read()).decode('utf-8')def api_calling(image, prompt, api_key):base64_image = encode_image(image)if len(prompt) == 0:49 unmodified lineswith block:gr.Markdown("""<h1><center>Visual Explorer - Ask and Learn about Images</center></h1> """)with gr.Row():with gr.Column(scale=0.5):img_input = gr.Image(type="filepath", label="Upload Image")api_input = gr.Textbox(label= "Enter Api-key")upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")with gr.Column():chatbot = gr.Chatbot(label="Chat with Image")message = gr.Textbox(label="User", placeholder=prompt)state = gr.State()upload_button.click(message_and_history, inputs=[img_input, message, state, api_input], outputs=[chatbot, state])message.submit(message_and_history, inputs=[img_input, message, state, api_input], outputs=[chatbot, state])message.submit(lambda: None, None, message, queue=False)block.launch()3 unmodified lines45678910111 unmodified line13141516171819202122232425262728293049 unmodified lines808182838485868788899091929394959697983 unmodified linesimport tempfileimport osimport openaiimport cv2import numpyprompt = "Type and press Enter"1 unmodified linewith open(image_path, "rb") as image_file:return base64.b64encode(image_file.read()).decode('utf-8')def mark_contours(image_path):image = cv2.imread(image_path)image = cv2.resize(image, (0, 0), fx = 0.5, fy = 0.5)gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)contours, hierarchy = cv2.findContours(binary, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)image_copy = image.copy()image_copy = cv2.drawContours(image_copy, contours, -1, (0, 255, 0), thickness=2, lineType=cv2.LINE_AA)cv2.imwrite('cont_image.jpg', image_copy)return 'cont_image.jpg'def api_calling(image, prompt, api_key):base64_image = encode_image(image)if len(prompt) == 0:49 unmodified lineswith block:gr.Markdown("""<h1><center>Visual Explorer - Ask and Learn about Images</center></h1> """)with gr.Row():with gr.Column():img_input = gr.Image(type="filepath", label="Upload Image")api_input = gr.Textbox(label= "Enter Api-key")upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")with gr.Column():output_img = gr.Image(type="filepath",label="Selected Images")with gr.Column():chatbot = gr.Chatbot(label="Chat with Image")message = gr.Textbox(label="User", placeholder=prompt)state = gr.State()upload_button.click(message_and_history, inputs=[img_input, message, state, api_input], outputs=[chatbot, state])upload_button.click(mark_contours, inputs=image_name, outputs=output_img)message.submit(message_and_history, inputs=[img_input, message, state, api_input], outputs=[chatbot, state])message.submit(lambda: None, None, message, queue=False)block.launch()
app.py+18-1