Spaces:
Runtime error
Runtime error
Update app.py
Browse files102 unmodified lines103104105106107108195 unmodified lines304305306307308309310102 unmodified linesexcept Exception as e :return f"{e}"def process_image(image_input):# Initialize the Gradio client with the URL of the Gradio serverclient = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")195 unmodified lines# Process image inputif image_input is not None:image_text = process_image(image_input)combined_text += "\n\n**Image Input:**\n" + image_text# Process audio input102 unmodified lines103104105106107108109110111112113114115116117118119120121122123124125126127128129130131195 unmodified lines327328329330331332333334335102 unmodified linesexcept Exception as e :return f"{e}"def save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):os.makedirs(output_dir)# Generate a unique file namefile_name = f"image_{int(time.time())}.png"file_path = os.path.join(output_dir, file_name)# Check the type of image_input and handle accordinglyif isinstance(image_input, np.ndarray): # If image_input is a NumPy arrayImage.fromarray(image_input).save(file_path)elif isinstance(image_input, Image.Image): # If image_input is a PIL imageimage_input.save(file_path)elif isinstance(image_input, str) and image_input.startswith('data:image'): # If image_input is a base64 stringimage_data = base64.b64decode(image_input.split(',')[1])with open(file_path, 'wb') as f:f.write(image_data)else:raise ValueError("Unsupported image format")return file_pathdef process_image(image_input):# Initialize the Gradio client with the URL of the Gradio serverclient = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")195 unmodified lines# Process image inputif image_input is not None:# Convert image_input to a file pathimage_file_path = save_image(image_input)image_text = process_image(image_file_path)combined_text += "\n\n**Image Input:**\n" + image_text# Process audio input
app.py+26-1