Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
#from transformers import AutoModelForCausalLM, AutoProcessor
|
3 |
+
|
4 |
+
# Load the model and processor
|
5 |
+
model_id = "microsoft/Phi-3-vision-128k-instruct"
|
6 |
+
#model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto", _attn_implementation='flash_attention_2')
|
7 |
+
#processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
8 |
+
|
9 |
+
# Define the function to generate text
|
10 |
+
def generate_text(image, prompt):
|
11 |
+
# Process the input
|
12 |
+
inputs = ""
|
13 |
+
|
14 |
+
# Generate the text
|
15 |
+
generation_args = {
|
16 |
+
"max_new_tokens": 500,
|
17 |
+
"temperature": 0.0,
|
18 |
+
"do_sample": False,
|
19 |
+
}
|
20 |
+
|
21 |
+
return image + prompt
|
22 |
+
|
23 |
+
# Create the Gradio application
|
24 |
+
gr.Interface(
|
25 |
+
fn=generate_text,
|
26 |
+
inputs=[
|
27 |
+
gr.Image(type="pil"),
|
28 |
+
gr.Textbox(label="Prompt")
|
29 |
+
],
|
30 |
+
outputs=gr.Textbox(),
|
31 |
+
title="Phi-3-Vision Model",
|
32 |
+
description="Generate text based on an image and prompt using the Phi-3-Vision model."
|
33 |
+
).launch(share=True)
|