os1187 commited on
Commit
ab9f628
·
verified ·
1 Parent(s): 659a935

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -4,28 +4,28 @@ from transformers import ViTFeatureExtractor, ViTModel
4
  from PIL import Image
5
  from transformers import AutoTokenizer, AutoModel
6
  import torch
 
7
 
8
-
9
-
10
- # Define custom CSS styles
11
- button_style = gr.style(
12
- padding="10px 20px",
13
- background="#007BFF",
14
- color="white",
15
- border="none",
16
- cursor="pointer",
17
- font_size="16px",
18
- margin="10px"
19
- )
20
 
21
  # Define layout with custom styles
22
  layout = [
23
  gr.Row([gr.File(label="Upload PDF", type="file")]),
24
- gr.Row([gr.Button("Generate Insights", type="submit", style=button_style)]),
25
  gr.Row([gr.Textbox("Placeholder for PDF insights", label="Insights", type="text")])
26
  ]
27
 
28
-
29
  # Function to get image embeddings using ViT
30
  def get_image_embeddings(image_path, model_name='google/vit-base-patch16-224'):
31
  feature_extractor = ViTFeatureExtractor.from_pretrained(model_name)
@@ -38,8 +38,6 @@ def get_image_embeddings(image_path, model_name='google/vit-base-patch16-224'):
38
  return embeddings
39
 
40
  # Function to convert PDF to images
41
- from pdf2image import convert_from_path
42
-
43
  def pdf_to_images(pdf_file, img_dir):
44
  images = convert_from_path(pdf_file)
45
 
@@ -52,7 +50,6 @@ def pdf_to_images(pdf_file, img_dir):
52
 
53
  print(f"Converted {len(images)} pages to images and saved in {img_dir}")
54
 
55
-
56
  # Function to get text embeddings using a transformer model
57
  def get_text_embeddings(text, model_name='bert-base-uncased'):
58
  tokenizer = AutoTokenizer.from_pretrained(model_name)
@@ -90,8 +87,9 @@ iface = gr.Interface(
90
  inputs=gr.File(label="Upload PDF", type="file"),
91
  outputs=gr.Textbox("Placeholder for PDF insights", label="Insights", type="text"),
92
  title="pdf-chatbot",
93
- description="Upload a PDF and receive insights based on its content."
 
94
  )
95
 
96
  if __name__ == "__main__":
97
- iface.launch()
 
4
  from PIL import Image
5
  from transformers import AutoTokenizer, AutoModel
6
  import torch
7
+ from pdf2image import convert_from_path
8
 
9
+ # CSS styles
10
+ css = """
11
+ .button {
12
+ padding: 10px 20px;
13
+ background: #007BFF;
14
+ color: white;
15
+ border: none;
16
+ cursor: pointer;
17
+ font-size: 16px;
18
+ margin: 10px;
19
+ }
20
+ """
21
 
22
  # Define layout with custom styles
23
  layout = [
24
  gr.Row([gr.File(label="Upload PDF", type="file")]),
25
+ gr.Row([gr.Button("Generate Insights", type="submit")]),
26
  gr.Row([gr.Textbox("Placeholder for PDF insights", label="Insights", type="text")])
27
  ]
28
 
 
29
  # Function to get image embeddings using ViT
30
  def get_image_embeddings(image_path, model_name='google/vit-base-patch16-224'):
31
  feature_extractor = ViTFeatureExtractor.from_pretrained(model_name)
 
38
  return embeddings
39
 
40
  # Function to convert PDF to images
 
 
41
  def pdf_to_images(pdf_file, img_dir):
42
  images = convert_from_path(pdf_file)
43
 
 
50
 
51
  print(f"Converted {len(images)} pages to images and saved in {img_dir}")
52
 
 
53
  # Function to get text embeddings using a transformer model
54
  def get_text_embeddings(text, model_name='bert-base-uncased'):
55
  tokenizer = AutoTokenizer.from_pretrained(model_name)
 
87
  inputs=gr.File(label="Upload PDF", type="file"),
88
  outputs=gr.Textbox("Placeholder for PDF insights", label="Insights", type="text"),
89
  title="pdf-chatbot",
90
+ description="Upload a PDF and receive insights based on its content.",
91
+ css=css # Add the CSS styles here
92
  )
93
 
94
  if __name__ == "__main__":
95
+ iface.launch()