Spaces:
Running
on
Zero
Running
on
Zero
from transformers import AutoConfig, AutoModel | |
import gradio as gr | |
import spaces | |
model_path = "turing-motors/Heron-NVILA-Lite-15B" | |
# or directly from_pretrained | |
model = AutoModel.from_pretrained(model_path, trust_remote_code=True, device_map="auto") | |
# examples generate using generation_config | |
from PIL import Image | |
import requests | |
from transformers import GenerationConfig | |
generation_config = { | |
"max_new_tokens": 2048, | |
"temperature": 0.5, | |
"do_sample": True, | |
} | |
generation_config = GenerationConfig(**generation_config) | |
DESCRIPTION = ''' | |
<div> | |
<h1 style="text-align: center;">非公式Heron-NVILA-Lite-15B</h1> | |
<p>Heron-NVILA-Lite-15Bの非公式デモだよ。 <a href="https://huggingface.co/turing-motors/Heron-NVILA-Lite-15B"><b>turing-motors/Heron-NVILA-Lite-15B</b></a>.</p> | |
</div> | |
''' | |
def infer(image): | |
response = model.generate_content( | |
[image, "画像を可能な限り詳細に説明してください。"], | |
generation_config=generation_config | |
) | |
return response | |
css = """ | |
h1 { | |
text-align: center; | |
display: block; | |
} | |
#col-container { | |
margin: 0 auto; | |
max-width: 520px; | |
} | |
""" | |
with gr.Blocks(fill_height=True, css=css) as demo: | |
with gr.Column(elem_id="col-container"): | |
gr.Markdown(DESCRIPTION) | |
image_input=gr.Image(type="pil", label="画像をアップロード") | |
run_button = gr.Button("画像の説明文を生成する", scale=0) | |
text_output=gr.Textbox(label="生成されたテキスト") | |
run_button.click( | |
fn = infer, | |
inputs = image_input, | |
outputs = text_output, | |
) | |
if __name__ == "__main__": | |
demo.launch(mcp_server=True) | |