LethalLuck commited on
Commit
0bef8f6
Β·
verified Β·
1 Parent(s): c8a3288

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,27 +1,37 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, AutoModelForVisionLanguage
3
  import torch
 
4
 
5
  MODEL_NAME = "Declan1/llava-v1.6-mistral-7b-sydneyfish-a100"
6
 
 
7
  processor = AutoProcessor.from_pretrained(MODEL_NAME)
8
- model = AutoModelForVisionLanguage.from_pretrained(
 
 
9
  MODEL_NAME,
10
  torch_dtype=torch.float16,
11
  device_map="auto"
12
  )
13
 
14
- def chat(image, text):
15
- inputs = processor(text=text, images=image, return_tensors="pt").to(model.device)
 
 
 
16
  output = model.generate(**inputs, max_new_tokens=300)
 
 
17
  response = processor.decode(output[0], skip_special_tokens=True)
18
  return response
19
 
20
- iface = gr.Interface(
 
21
  fn=chat,
22
- inputs=[gr.Image(type="pil"), gr.Textbox(label="Prompt")],
23
  outputs=gr.Textbox(label="Response"),
24
- title="SydneyFish LLaVA 1.6 - Mistral 7B"
 
25
  )
26
 
27
- iface.launch()
 
1
  import gradio as gr
 
2
  import torch
3
+ from transformers import AutoProcessor, LlavaForConditionalGeneration
4
 
5
  MODEL_NAME = "Declan1/llava-v1.6-mistral-7b-sydneyfish-a100"
6
 
7
+ # Load processor (handles image + text formatting)
8
  processor = AutoProcessor.from_pretrained(MODEL_NAME)
9
+
10
+ # Load model (Vision + Language fused)
11
+ model = LlavaForConditionalGeneration.from_pretrained(
12
  MODEL_NAME,
13
  torch_dtype=torch.float16,
14
  device_map="auto"
15
  )
16
 
17
+ def chat(image, prompt):
18
+ # Process inputs
19
+ inputs = processor(prompt, images=image, return_tensors="pt").to(model.device)
20
+
21
+ # Generate output
22
  output = model.generate(**inputs, max_new_tokens=300)
23
+
24
+ # Decode to readable text
25
  response = processor.decode(output[0], skip_special_tokens=True)
26
  return response
27
 
28
+ # Simple UI
29
+ interface = gr.Interface(
30
  fn=chat,
31
+ inputs=[gr.Image(type="pil", label="Image"), gr.Textbox(label="Prompt")],
32
  outputs=gr.Textbox(label="Response"),
33
+ title="SydneyFish LLaVA (Mistral 7B)",
34
+ description="Upload an image and ask it something."
35
  )
36
 
37
+ interface.launch()