PattananKKK commited on
Commit
36af6b6
·
verified ·
1 Parent(s): fa84fdd

upload files

Browse files
Files changed (4) hide show
  1. README copy.md +12 -0
  2. adapter_config.json +34 -0
  3. adapter_model.safetensors +3 -0
  4. app.py +40 -0
README copy.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Final Instagram Caption Model
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
adapter_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": {
4
+ "base_model_class": "GitForCausalLM",
5
+ "parent_library": "transformers.models.git.modeling_git"
6
+ },
7
+ "base_model_name_or_path": "microsoft/git-base",
8
+ "bias": "none",
9
+ "fan_in_fan_out": false,
10
+ "inference_mode": true,
11
+ "init_lora_weights": true,
12
+ "layer_replication": null,
13
+ "layers_pattern": null,
14
+ "layers_to_transform": null,
15
+ "loftq_config": {},
16
+ "lora_alpha": 8,
17
+ "lora_dropout": 0.0,
18
+ "megatron_config": null,
19
+ "megatron_core": "megatron.core",
20
+ "modules_to_save": [
21
+ "classifier"
22
+ ],
23
+ "peft_type": "LORA",
24
+ "r": 8,
25
+ "rank_pattern": {},
26
+ "revision": null,
27
+ "target_modules": [
28
+ "value",
29
+ "query"
30
+ ],
31
+ "task_type": null,
32
+ "use_dora": false,
33
+ "use_rslora": false
34
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:43229defd2d74cf95ce3eeb187b493d6a409cf75b93ed92f9eb077e9347a6c25
3
+ size 593144
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import pipeline, AutoProcessor, AutoModelForCausalLM
3
+ import gradio as gr
4
+ import torch
5
+
6
+ processor = AutoProcessor.from_pretrained("microsoft/git-base")
7
+ model = AutoModelForCausalLM.from_pretrained('./')
8
+
9
+ def predict(image):
10
+ # Prepare the image using the processor
11
+ inputs = processor(images=image, return_tensors="pt")
12
+
13
+ # Move inputs to the appropriate device
14
+ device = "cuda" if torch.cuda.is_available() else "cpu"
15
+ inputs = {key: value.to(device) for key, value in inputs.items()}
16
+ model.to(device)
17
+
18
+ # Generate the caption
19
+ outputs = model.generate(**inputs)
20
+
21
+ # Decode the generated caption
22
+ caption = processor.batch_decode(outputs, skip_special_tokens=True)[0]
23
+
24
+ return caption
25
+
26
+
27
+ with gr.Blocks() as demo:
28
+ image = gr.Image(type="pil")
29
+ predict_btn = gr.Button("Predict", variant="primary")
30
+ output = gr.Label(label="Generated Caption")
31
+
32
+ inputs = [image]
33
+ outputs = [output]
34
+
35
+ predict_btn.click(predict, inputs=inputs, outputs=outputs)
36
+
37
+ if __name__ == "__main":
38
+ demo.launch() # Local machine only
39
+ # demo.launch(server_name="0.0.0.0") # LAN access to local machine
40
+ # demo.launch(share=True) # Public access to local machine