mateoluksenberg commited on
Commit
5d57345
1 Parent(s): aaf15d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -11
app.py CHANGED
@@ -92,31 +92,61 @@ def extract_pptx(path):
92
  return text
93
 
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  def mode_load(path):
96
  choice = ""
97
- file_type = path.split(".")[-1]
98
  print(file_type)
 
99
  if file_type in ["pdf", "txt", "py", "docx", "pptx", "json", "cpp", "md"]:
100
- if file_type.endswith("pdf"):
101
  content = extract_pdf(path)
102
- elif file_type.endswith("docx"):
103
  content = extract_docx(path)
104
- elif file_type.endswith("pptx"):
105
  content = extract_pptx(path)
106
  else:
107
  content = extract_text(path)
108
  choice = "doc"
109
  print(content[:100])
110
  return choice, content[:5000]
111
-
112
-
113
  elif file_type in ["png", "jpg", "jpeg", "bmp", "tiff", "webp"]:
114
- content = Image.open(path).convert('RGB')
115
- choice = "image"
116
- return choice, content
117
-
 
 
 
118
  else:
119
- raise gr.Error("Oops, unsupported files.")
120
 
121
 
122
  @spaces.GPU()
 
92
  return text
93
 
94
 
95
+ # def mode_load(path):
96
+ # choice = ""
97
+ # file_type = path.split(".")[-1]
98
+ # print(file_type)
99
+ # if file_type in ["pdf", "txt", "py", "docx", "pptx", "json", "cpp", "md"]:
100
+ # if file_type.endswith("pdf"):
101
+ # content = extract_pdf(path)
102
+ # elif file_type.endswith("docx"):
103
+ # content = extract_docx(path)
104
+ # elif file_type.endswith("pptx"):
105
+ # content = extract_pptx(path)
106
+ # else:
107
+ # content = extract_text(path)
108
+ # choice = "doc"
109
+ # print(content[:100])
110
+ # return choice, content[:5000]
111
+
112
+
113
+ # elif file_type in ["png", "jpg", "jpeg", "bmp", "tiff", "webp"]:
114
+ # content = Image.open(path).convert('RGB')
115
+ # choice = "image"
116
+ # return choice, content
117
+
118
+ # else:
119
+ # raise gr.Error("Oops, unsupported files.")
120
+
121
+
122
  def mode_load(path):
123
  choice = ""
124
+ file_type = path.split(".")[-1].lower()
125
  print(file_type)
126
+
127
  if file_type in ["pdf", "txt", "py", "docx", "pptx", "json", "cpp", "md"]:
128
+ if file_type == "pdf":
129
  content = extract_pdf(path)
130
+ elif file_type == "docx":
131
  content = extract_docx(path)
132
+ elif file_type == "pptx":
133
  content = extract_pptx(path)
134
  else:
135
  content = extract_text(path)
136
  choice = "doc"
137
  print(content[:100])
138
  return choice, content[:5000]
139
+
 
140
  elif file_type in ["png", "jpg", "jpeg", "bmp", "tiff", "webp"]:
141
+ try:
142
+ content = Image.open(path).convert('RGB')
143
+ choice = "image"
144
+ return choice, content
145
+ except Exception as e:
146
+ raise ValueError(f"Error processing image file: {e}")
147
+
148
  else:
149
+ raise ValueError("Oops, unsupported file type.")
150
 
151
 
152
  @spaces.GPU()