PattananKKK commited on
Commit
6a2fcdf
·
verified ·
1 Parent(s): 39c47f5

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -46
app.py DELETED
@@ -1,46 +0,0 @@
1
-
2
- from transformers import AutoProcessor, AutoModelForCausalLM
3
- import gradio as gr
4
- import torch
5
-
6
- # Load the processor and model
7
- processor = AutoProcessor.from_pretrained("microsoft/git-base")
8
- model = AutoModelForCausalLM.from_pretrained("./")
9
-
10
- def predict(image):
11
- try:
12
- # Prepare the image using the processor
13
- inputs = processor(images=image, return_tensors="pt")
14
-
15
- # Move inputs to the appropriate device
16
- device = "cuda" if torch.cuda.is_available() else "cpu"
17
- inputs = {key: value.to(device) for key, value in inputs.items()}
18
- model.to(device)
19
-
20
- # Generate the caption
21
- outputs = model.generate(**inputs)
22
-
23
- # Decode the generated caption
24
- caption = processor.batch_decode(outputs, skip_special_tokens=True)[0]
25
-
26
- return caption
27
-
28
- except Exception as e:
29
- print("Error during prediction:", str(e))
30
- return "Error: " + str(e)
31
-
32
- # https://www.gradio.app/guides
33
- with gr.Blocks() as demo:
34
- image = gr.Image(type="pil")
35
- predict_btn = gr.Button("Predict", variant="primary")
36
- output = gr.Label(label="Generated Caption")
37
-
38
- inputs = [image]
39
- outputs = [output]
40
-
41
- predict_btn.click(predict, inputs=inputs, outputs=outputs)
42
-
43
- if __name__ == "__main__":
44
- demo.launch() # Local machine only
45
- # demo.launch(server_name="0.0.0.0") # LAN access to local machine
46
- # demo.launch(share=True) # Public access to local machine