virendravaishnav commited on
Commit
31385fe
·
1 Parent(s): 7e3bba1

Updated with OCR model and Gradio integration

Browse files
Files changed (1) hide show
  1. app.py +3 -27
app.py CHANGED
@@ -1,34 +1,10 @@
1
  import gradio as gr
2
- from huggingface_hub import hf_hub_download
3
- from transformers import AutoTokenizer
4
- import importlib.util
5
- import sys
6
 
7
- # Define the repository name
8
- repo_id = "OpenGVLab/InternVL2-1B"
9
-
10
- # Download the correct files by inspecting the repository
11
- config_file = hf_hub_download(repo_id=repo_id, filename="configuration_internvl_chat.py", local_dir="model_files")
12
- model_file = hf_hub_download(repo_id=repo_id, filename="modeling_internvl_chat.py", local_dir="model_files")
13
-
14
- # Add the model_files directory to sys.path to enable absolute imports
15
- sys.path.append("model_files")
16
-
17
- # Load the configuration file dynamically
18
- spec_config = importlib.util.spec_from_file_location("InternVLChatConfig", config_file)
19
- InternVLChatConfig = importlib.util.module_from_spec(spec_config)
20
- spec_config.loader.exec_module(InternVLChatConfig)
21
-
22
- # Load the model file dynamically
23
- spec_model = importlib.util.spec_from_file_location("InternVLForVision2Seq", model_file)
24
- InternVLForVision2Seq = importlib.util.module_from_spec(spec_model)
25
- spec_model.loader.exec_module(InternVLForVision2Seq)
26
-
27
- # Load the tokenizer and model
28
  model_name = "OpenGVLab/InternVL2-1B"
29
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
30
- config = InternVLChatConfig.InternVLChatConfig.from_pretrained(model_name, trust_remote_code=True)
31
- model = InternVLForVision2Seq.InternVLForVision2Seq.from_pretrained(model_name, config=config, trust_remote_code=True)
32
 
33
  # Function to process and describe the image
34
  def analyze_image(image):
 
1
  import gradio as gr
2
+ from transformers import AutoModelForVision2Seq, AutoTokenizer
 
 
 
3
 
4
+ # Load the Hugging Face model and tokenizer, trusting remote code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  model_name = "OpenGVLab/InternVL2-1B"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
7
+ model = AutoModelForVision2Seq.from_pretrained(model_name, trust_remote_code=True)
 
8
 
9
  # Function to process and describe the image
10
  def analyze_image(image):