Ozgur Unlu commited on
Commit
8e69166
·
1 Parent(s): d85117b

more fixes

Browse files
Files changed (2) hide show
  1. app.py +19 -64
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,32 +1,6 @@
1
- import torch
2
- import sys
3
- import subprocess
4
-
5
- def check_gpu_status():
6
- print("Python version:", sys.version)
7
- print("PyTorch version:", torch.__version__)
8
- print("CUDA available:", torch.cuda.is_available())
9
- print("CUDA version:", torch.version.cuda if torch.cuda.is_available() else "Not available")
10
-
11
- if torch.cuda.is_available():
12
- print("GPU Device:", torch.cuda.get_device_name(0))
13
- print("GPU Memory:", torch.cuda.get_device_properties(0).total_memory / 1024**3, "GB")
14
-
15
- try:
16
- nvidia_smi = subprocess.check_output(["nvidia-smi"])
17
- print("nvidia-smi output:")
18
- print(nvidia_smi.decode())
19
- except:
20
- print("nvidia-smi not available")
21
-
22
- # Run GPU check at startup
23
- print("=== GPU Status Check ===")
24
- check_gpu_status()
25
- print("======================")
26
-
27
- # Rest of your imports
28
  import gradio as gr
29
  import easyocr
 
30
  from transformers import pipeline, DistilBertTokenizer, DistilBertForSequenceClassification
31
  import numpy as np
32
  from PIL import Image
@@ -40,21 +14,8 @@ if torch.cuda.is_available():
40
  else:
41
  print("Running on CPU")
42
 
43
- # Set device
44
- device = "cuda" if torch.cuda.is_available() else "cpu"
45
- print(f"Using device: {device}")
46
-
47
- # Initialize OCR reader with device specification
48
- try:
49
- reader = easyocr.Reader(['en'], gpu=torch.cuda.is_available())
50
- print("EasyOCR initialized successfully")
51
- except Exception as e:
52
- print(f"Error initializing EasyOCR: {str(e)}")
53
- reader = easyocr.Reader(['en'], gpu=False)
54
- print("Falling back to CPU for EasyOCR")
55
-
56
  # Initialize OCR reader
57
- reader = easyocr.Reader(['en'])
58
 
59
  # Initialize compliance rules
60
  compliance_rules = ComplianceRules()
@@ -164,31 +125,25 @@ def analyze_ad_copy(image):
164
 
165
  return report_text
166
 
167
- # Create Gradio interface
168
- iface = gr.Interface(
169
  fn=analyze_ad_copy,
170
- inputs=[
171
- gr.Image(
172
- type="pil",
173
- label="Upload Marketing Material",
174
- height=300,
175
- width=400,
176
- image_mode="RGB",
177
- scale=1,
178
- source="upload",
179
- tool="select"
180
- )
181
- ],
182
- outputs=gr.Textbox(label="Compliance Report", lines=10),
183
  title="Marketing Campaign Compliance Checker",
184
  description="Upload marketing material to check compliance with US (SEC), UK (FCA), and EU financial regulations.",
185
- examples=[],
186
- theme=gr.themes.Base(),
187
- allow_flagging="never"
188
  )
189
 
190
- # Launch the app with additional error handling
191
- try:
192
- iface.launch(debug=True)
193
- except Exception as e:
194
- print(f"Error launching interface: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import easyocr
3
+ import torch
4
  from transformers import pipeline, DistilBertTokenizer, DistilBertForSequenceClassification
5
  import numpy as np
6
  from PIL import Image
 
14
  else:
15
  print("Running on CPU")
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Initialize OCR reader
18
+ reader = easyocr.Reader(['en'], gpu=torch.cuda.is_available())
19
 
20
  # Initialize compliance rules
21
  compliance_rules = ComplianceRules()
 
125
 
126
  return report_text
127
 
128
+ # Create Gradio interface with updated parameters
129
+ demo = gr.Interface(
130
  fn=analyze_ad_copy,
131
+ inputs=gr.Image(
132
+ type="numpy",
133
+ label="Upload Marketing Material",
134
+ height=300,
135
+ width=400,
136
+ ),
137
+ outputs=gr.Textbox(
138
+ label="Compliance Report",
139
+ lines=10,
140
+ max_lines=20
141
+ ),
 
 
142
  title="Marketing Campaign Compliance Checker",
143
  description="Upload marketing material to check compliance with US (SEC), UK (FCA), and EU financial regulations.",
144
+ theme=gr.themes.Default()
 
 
145
  )
146
 
147
+ # Launch the app
148
+ if __name__ == "__main__":
149
+ demo.launch()
 
 
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- torch
2
  torchvision
3
  gradio>=4.8.0
4
  easyocr
 
1
+ torch>=2.0.0
2
  torchvision
3
  gradio>=4.8.0
4
  easyocr