mehdi364 commited on
Commit
c49b90d
·
verified ·
1 Parent(s): a2cf0b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -12
app.py CHANGED
@@ -5,7 +5,6 @@ from langchain.text_splitter import CharacterTextSplitter
5
  from langchain_community.vectorstores import FAISS
6
  from langchain_community.llms import HuggingFaceHub
7
  import pandas as pd
8
- import logging
9
 
10
  # Set API token for HuggingFace
11
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = os.getenv('HUGGINGFACEHUB_API_TOKEN', "")
@@ -13,9 +12,6 @@ os.environ["HUGGINGFACEHUB_API_TOKEN"] = os.getenv('HUGGINGFACEHUB_API_TOKEN', "
13
  # Initialize Dash app
14
  app = Dash(__name__)
15
 
16
- # Configure logging
17
- logging.basicConfig(level=logging.DEBUG)
18
-
19
  # Extract text from PDF files
20
  def get_pdf_text(pdf_file):
21
  try:
@@ -122,15 +118,11 @@ def handle_question(n_clicks_answer, question, n_clicks_process):
122
  [State('upload-pdf', 'contents'), State('upload-csv', 'contents')]
123
  )
124
  def process_files(n_clicks, pdf_contents, csv_contents):
125
- logging.debug(f"PDF Contents: {pdf_contents}")
126
- logging.debug(f"CSV Contents: {csv_contents}")
127
-
128
  if n_clicks > 0:
129
  combined_text = ""
130
 
131
  if pdf_contents:
132
  if not isinstance(pdf_contents, list) or not all(isinstance(content, str) for content in pdf_contents):
133
- logging.error("Invalid PDF format.")
134
  return "فرمت فایل PDF صحیح نیست. لطفاً دوباره تلاش کنید."
135
  for content in pdf_contents:
136
  try:
@@ -138,7 +130,6 @@ def process_files(n_clicks, pdf_contents, csv_contents):
138
  pdf_text = get_pdf_text(pdf_data)
139
  combined_text += pdf_text
140
  except Exception as e:
141
- logging.error(f"Error processing PDF: {e}")
142
  return f"خطا در پردازش فایل PDF: {str(e)}"
143
 
144
  if csv_contents:
@@ -148,11 +139,9 @@ def process_files(n_clicks, pdf_contents, csv_contents):
148
  csv_text = process_csv_data(csv_data)
149
  combined_text += csv_text
150
  except Exception as e:
151
- logging.error(f"Error processing CSV: {e}")
152
  return f"خطا در پردازش فایل CSV: {str(e)}"
153
 
154
  if not combined_text.strip():
155
- logging.warning("No text found for processing.")
156
  return "هیچ متنی برای پردازش یافت نشد."
157
 
158
  try:
@@ -162,7 +151,6 @@ def process_files(n_clicks, pdf_contents, csv_contents):
162
  app.server.config['conversation_chain'] = conversation_chain
163
  return "پردازش تکمیل شد! اکنون می‌توانید سوالات خود را بپرسید."
164
  except ValueError as e:
165
- logging.error(f"Error during processing: {e}")
166
  return f"خطا در پردازش داده‌ها: {str(e)}"
167
 
168
  return "لطفاً فایل‌های مناسب را آپلود کنید."
 
5
  from langchain_community.vectorstores import FAISS
6
  from langchain_community.llms import HuggingFaceHub
7
  import pandas as pd
 
8
 
9
  # Set API token for HuggingFace
10
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = os.getenv('HUGGINGFACEHUB_API_TOKEN', "")
 
12
  # Initialize Dash app
13
  app = Dash(__name__)
14
 
 
 
 
15
  # Extract text from PDF files
16
  def get_pdf_text(pdf_file):
17
  try:
 
118
  [State('upload-pdf', 'contents'), State('upload-csv', 'contents')]
119
  )
120
  def process_files(n_clicks, pdf_contents, csv_contents):
 
 
 
121
  if n_clicks > 0:
122
  combined_text = ""
123
 
124
  if pdf_contents:
125
  if not isinstance(pdf_contents, list) or not all(isinstance(content, str) for content in pdf_contents):
 
126
  return "فرمت فایل PDF صحیح نیست. لطفاً دوباره تلاش کنید."
127
  for content in pdf_contents:
128
  try:
 
130
  pdf_text = get_pdf_text(pdf_data)
131
  combined_text += pdf_text
132
  except Exception as e:
 
133
  return f"خطا در پردازش فایل PDF: {str(e)}"
134
 
135
  if csv_contents:
 
139
  csv_text = process_csv_data(csv_data)
140
  combined_text += csv_text
141
  except Exception as e:
 
142
  return f"خطا در پردازش فایل CSV: {str(e)}"
143
 
144
  if not combined_text.strip():
 
145
  return "هیچ متنی برای پردازش یافت نشد."
146
 
147
  try:
 
151
  app.server.config['conversation_chain'] = conversation_chain
152
  return "پردازش تکمیل شد! اکنون می‌توانید سوالات خود را بپرسید."
153
  except ValueError as e:
 
154
  return f"خطا در پردازش داده‌ها: {str(e)}"
155
 
156
  return "لطفاً فایل‌های مناسب را آپلود کنید."