Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
from preprocessing import read_file
|
|
|
|
| 4 |
|
| 5 |
def process_file(files, topic):
|
| 6 |
"""
|
|
@@ -38,7 +39,11 @@ def process_file(files, topic):
|
|
| 38 |
|
| 39 |
"""
|
| 40 |
# progress = gr.Progress()
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
log_history = [] # To store logs for each file
|
| 43 |
for i, file in enumerate(files):
|
| 44 |
# progress(i / len(files), desc=f"Processing file {i + 1}/{len(files)}: {file_path}")
|
|
@@ -48,16 +53,20 @@ def process_file(files, topic):
|
|
| 48 |
file_path = file.name
|
| 49 |
text = read_file(file_path)
|
| 50 |
print(f"for file {file_path}", text[:1000])
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
# Spl
|
| 53 |
# Save chunks to database
|
| 54 |
-
|
| 55 |
|
| 56 |
log_history.append( f"File {file_path} processed successfully! file saved to the database.")
|
| 57 |
except Exception as e:
|
| 58 |
log_history.append( f"Error processing for file {file_path}: {str(e)}")
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
# progress(1.0, desc="Processing complete!")
|
| 62 |
return "\n".join(log_history)
|
| 63 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from utils import update_db_hub
|
| 3 |
from preprocessing import read_file
|
| 4 |
+
import datetime
|
| 5 |
|
| 6 |
def process_file(files, topic):
|
| 7 |
"""
|
|
|
|
| 39 |
|
| 40 |
"""
|
| 41 |
# progress = gr.Progress()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
texts = []
|
| 45 |
+
topics = []
|
| 46 |
+
dates = []
|
| 47 |
log_history = [] # To store logs for each file
|
| 48 |
for i, file in enumerate(files):
|
| 49 |
# progress(i / len(files), desc=f"Processing file {i + 1}/{len(files)}: {file_path}")
|
|
|
|
| 53 |
file_path = file.name
|
| 54 |
text = read_file(file_path)
|
| 55 |
print(f"for file {file_path}", text[:1000])
|
| 56 |
+
texts.append(text)
|
| 57 |
+
topics.append(topic)
|
| 58 |
+
dates.append(datetime.datetime.now().isoformat())
|
| 59 |
# Spl
|
| 60 |
# Save chunks to database
|
| 61 |
+
|
| 62 |
|
| 63 |
log_history.append( f"File {file_path} processed successfully! file saved to the database.")
|
| 64 |
except Exception as e:
|
| 65 |
log_history.append( f"Error processing for file {file_path}: {str(e)}")
|
| 66 |
|
| 67 |
+
print("save in db")
|
| 68 |
+
update_db_hub(texts, topics, dates)
|
| 69 |
+
print('saved')
|
| 70 |
# progress(1.0, desc="Processing complete!")
|
| 71 |
return "\n".join(log_history)
|
| 72 |
|