mynkchaudhry commited on
Commit
cc9f8b9
1 Parent(s): 2989a3a

upload all the files

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -1,22 +1,25 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoProcessor
3
- from PIL import Image
4
  import torch
 
 
 
 
 
 
 
5
 
6
  # Load model and processor with trust_remote_code=True
7
- try:
8
- model = AutoModelForCausalLM.from_pretrained(
9
- "mynkchaudhry/Florence-2-FT-DocVQA",
10
- force_download=True,
11
- trust_remote_code=True
12
- )
13
- processor = AutoProcessor.from_pretrained(
14
- "mynkchaudhry/Florence-2-FT-DocVQA",
15
- force_download=True,
16
- trust_remote_code=True
17
- )
18
- except Exception as e:
19
- raise RuntimeError(f"Error loading model or processor: {e}")
20
 
21
  def generate_response(image, question):
22
  try:
@@ -42,11 +45,11 @@ def generate_response(image, question):
42
  except Exception as e:
43
  return f"Error processing image: {e}"
44
 
45
- # Example images for demonstration (ensure paths are correct and files are accessible)
46
  examples = [
47
- [Image.open("demo.png"), "what is the address in the page?"],
48
- [Image.open("demo2.jpg"), "what is the date in the page?"],
49
- [Image.open("demo.png"), "what is the name in the page?"]
50
  ]
51
 
52
  # Gradio interface
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
 
3
  import torch
4
+ from PIL import Image
5
+
6
+ # Custom configuration class
7
+ class Florence2Config(AutoConfig):
8
+ def to_dict(self):
9
+ config_dict = super().to_dict()
10
+ return config_dict
11
 
12
  # Load model and processor with trust_remote_code=True
13
+ model = AutoModelForCausalLM.from_pretrained(
14
+ "mynkchaudhry/Florence-2-FT-DocVQA",
15
+ force_download=True,
16
+ trust_remote_code=True
17
+ )
18
+ processor = AutoProcessor.from_pretrained(
19
+ "mynkchaudhry/Florence-2-FT-DocVQA",
20
+ force_download=True,
21
+ trust_remote_code=True
22
+ )
 
 
 
23
 
24
  def generate_response(image, question):
25
  try:
 
45
  except Exception as e:
46
  return f"Error processing image: {e}"
47
 
48
+ # Example images for demonstration (update paths as needed)
49
  examples = [
50
+ ["demo.png", "what is the address in the page?"],
51
+ ["demo2.jpg", "what is the date in the page?"],
52
+ ["demo.png", "what is the name in the page?"]
53
  ]
54
 
55
  # Gradio interface