Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,8 +34,8 @@ model = AutoModel.from_pretrained("unum-cloud/uform-gen2-dpo", trust_remote_code
|
|
| 34 |
processor = AutoProcessor.from_pretrained("unum-cloud/uform-gen2-dpo", trust_remote_code=True)
|
| 35 |
|
| 36 |
@spaces.GPU(duration=10, queue=False)
|
| 37 |
-
def
|
| 38 |
-
inputs = processor(text=[
|
| 39 |
with torch.inference_mode():
|
| 40 |
output = model.generate(
|
| 41 |
**inputs,
|
|
@@ -45,11 +45,11 @@ def answer_question(image3, prompt3):
|
|
| 45 |
eos_token_id=151645,
|
| 46 |
pad_token_id=processor.tokenizer.pad_token_id
|
| 47 |
)
|
|
|
|
| 48 |
prompt_len = inputs["input_ids"].shape[1]
|
| 49 |
decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
|
| 50 |
-
return decoded_text
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
|
| 55 |
theme = gr.themes.Base(
|
|
@@ -545,10 +545,10 @@ with gr.Blocks() as video:
|
|
| 545 |
gr.Markdown(" ## Live Chat")
|
| 546 |
gr.Markdown("### Click camera option to update image")
|
| 547 |
gr.Interface(
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
)
|
| 552 |
|
| 553 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}", title="GPT 4o DEMO") as demo:
|
| 554 |
gr.Markdown("# OpenGPT 4o")
|
|
|
|
| 34 |
processor = AutoProcessor.from_pretrained("unum-cloud/uform-gen2-dpo", trust_remote_code=True)
|
| 35 |
|
| 36 |
@spaces.GPU(duration=10, queue=False)
|
| 37 |
+
def generate_caption(image, prompt):
|
| 38 |
+
inputs = processor(text=[prompt], images=[image], return_tensors="pt")
|
| 39 |
with torch.inference_mode():
|
| 40 |
output = model.generate(
|
| 41 |
**inputs,
|
|
|
|
| 45 |
eos_token_id=151645,
|
| 46 |
pad_token_id=processor.tokenizer.pad_token_id
|
| 47 |
)
|
| 48 |
+
|
| 49 |
prompt_len = inputs["input_ids"].shape[1]
|
| 50 |
decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
|
|
|
|
| 51 |
|
| 52 |
+
yield decoded_text
|
| 53 |
|
| 54 |
|
| 55 |
theme = gr.themes.Base(
|
|
|
|
| 545 |
gr.Markdown(" ## Live Chat")
|
| 546 |
gr.Markdown("### Click camera option to update image")
|
| 547 |
gr.Interface(
|
| 548 |
+
fn=generate_caption,
|
| 549 |
+
inputs=[gr.Image(type="pil", label="Upload Image"), gr.Textbox(label="Prompt", value="what he is doing")],
|
| 550 |
+
outputs=gr.Textbox(label="Answer"),
|
| 551 |
+
)
|
| 552 |
|
| 553 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}", title="GPT 4o DEMO") as demo:
|
| 554 |
gr.Markdown("# OpenGPT 4o")
|