Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import google.generativeai as genai | |
| from PIL import Image | |
| import io | |
| import numpy as np | |
| def generate_content(api_key, prompt, image_data): | |
| genai.configure(api_key=api_key) | |
| # Convert uploaded binary data into a PIL image. | |
| # image = Image.open(io.BytesIO(image_data)) | |
| image = Image.fromarray(np.uint8(image_data)).convert('RGB') | |
| model = genai.GenerativeModel('gemini-pro-vision') | |
| response = model.generate_content([prompt, image]) | |
| response.resolve() | |
| return response.text | |
| with gr.Blocks() as app: | |
| gr.Markdown("# gemini-pro-vision demo") | |
| gr.Markdown("This is a simple example of image understanding, supporting the upload of only one image,Enter your API key to start the conversation. Get a free API key from here: https://ai.google.dev/") | |
| api_key_input = gr.Textbox(label="API Key", type="password", placeholder="Enter your API Key", lines=1) | |
| # image_input = gr.File(label="Upload an image", type="binary") | |
| image_input = gr.Image(label="Upload an image") | |
| prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your Prompt", value="Describe this picture",lines=3) | |
| generate_button = gr.Button("Generate Content") | |
| output = gr.Markdown() | |
| generate_button.click( | |
| generate_content, | |
| inputs=[api_key_input, prompt_input, image_input], | |
| outputs=output | |
| ) | |
| app.launch() | |