guneetsk99 commited on
Commit
512e1cc
·
verified ·
1 Parent(s): c29054e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoProcessor, AutoModelForImageTextToText
3
+ from PIL import Image
4
+
5
+ # Load model and processor
6
+ processor = AutoProcessor.from_pretrained("guneetsk99/finance_qwen_VL_7B")
7
+ model = AutoModelForImageTextToText.from_pretrained("guneetsk99/finance_qwen_VL_7B")
8
+
9
+ def predict(input_img):
10
+ # Preprocess the image
11
+ inputs = processor(images=input_img, return_tensors="pt")
12
+
13
+ # Generate predictions using the model
14
+ outputs = model.generate(**inputs)
15
+
16
+ # Decode the generated text
17
+ generated_text = processor.decode(outputs[0], skip_special_tokens=True)
18
+
19
+ # Return the input image and the generated text
20
+ return input_img, {"Prediction": generated_text}
21
+
22
+ # Create the Gradio interface
23
+ gradio_app = gr.Interface(
24
+ predict,
25
+ inputs=gr.Image(label="Upload Image", source="upload", type="pil"),
26
+ outputs=[
27
+ gr.Image(label="Uploaded Image"),
28
+ gr.Label(label="Generated Text"),
29
+ ],
30
+ title="Image to Text Model",
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ gradio_app.launch()