Spaces:
Runtime error
Runtime error
from qwenvl import QwenVLModel | |
import gradio as gr | |
from PIL import Image | |
import datetime | |
import os | |
import numpy as np | |
model = QwenVLModel() | |
DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)" | |
def array_to_image_path(image_array): | |
# Convert numpy array to PIL Image | |
img = Image.fromarray(np.uint8(image_array)) | |
# Generate a unique filename using timestamp | |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
filename = f"image_{timestamp}.png" | |
# Save the image | |
img.save(filename) | |
# Get the full path of the saved image | |
full_path = os.path.abspath(filename) | |
return full_path | |
css = """ | |
#output { | |
height: 500px; | |
overflow: auto; | |
border: 1px solid #ccc; | |
} | |
""" | |
with gr.Blocks(css=css) as demo: | |
gr.Markdown(DESCRIPTION) | |
with gr.Tab(label="Qwen2-VL-7B Input"): | |
with gr.Row(): | |
with gr.Column(): | |
input_img_arr = gr.Image(label="Input Picture") | |
input_img = Image.fromarray(input_img_arr).convert("RGB") | |
text_input = gr.Textbox(label="Question") | |
submit_btn = gr.Button(value="Submit") | |
with gr.Column(): | |
output_text = gr.Textbox(label="Output Text") | |
submit_btn.click(model.oneImagecall, [input_img, text_input], [output_text]) | |
demo.queue(api_open=False) | |
demo.launch(debug=True) |