Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,12 @@ import logging
|
|
5 |
from tqdm import tqdm
|
6 |
import gradio as gr
|
7 |
from transformers import pipeline
|
8 |
-
from huggingface_hub import HfApi, upload_file
|
9 |
|
10 |
# Setup Logging
|
11 |
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
12 |
|
13 |
-
# Download NLTK Data
|
14 |
nltk.download('all')
|
15 |
|
16 |
# Constants
|
@@ -40,12 +40,11 @@ def process_text(text):
|
|
40 |
|
41 |
def save_to_csv(data, filename="output.csv"):
|
42 |
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
|
43 |
-
writer = csv.DictWriter(csvfile, fieldnames=["word", "
|
44 |
writer.writeheader()
|
45 |
for word in data['words']:
|
46 |
writer.writerow({
|
47 |
"word": word,
|
48 |
-
"tokenizer": data['tokenizer'],
|
49 |
"meanings": str(data['meaning'][word])
|
50 |
})
|
51 |
|
@@ -64,28 +63,58 @@ def generate_report():
|
|
64 |
def generate_all(text):
|
65 |
data = process_text(text)
|
66 |
save_to_csv(data)
|
67 |
-
return
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# Run and Push to HuggingFace
|
79 |
def run_and_push():
|
80 |
train_dataset()
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
iface.launch()
|
|
|
5 |
from tqdm import tqdm
|
6 |
import gradio as gr
|
7 |
from transformers import pipeline
|
8 |
+
from huggingface_hub import HfApi, upload_file, HfFolder
|
9 |
|
10 |
# Setup Logging
|
11 |
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
12 |
|
13 |
+
# Download All NLTK Data
|
14 |
nltk.download('all')
|
15 |
|
16 |
# Constants
|
|
|
40 |
|
41 |
def save_to_csv(data, filename="output.csv"):
|
42 |
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
|
43 |
+
writer = csv.DictWriter(csvfile, fieldnames=["word", "meanings"])
|
44 |
writer.writeheader()
|
45 |
for word in data['words']:
|
46 |
writer.writerow({
|
47 |
"word": word,
|
|
|
48 |
"meanings": str(data['meaning'][word])
|
49 |
})
|
50 |
|
|
|
63 |
def generate_all(text):
|
64 |
data = process_text(text)
|
65 |
save_to_csv(data)
|
66 |
+
return "Processed data saved to output.csv"
|
67 |
|
68 |
+
# Custom CSS for Tailwind CSS
|
69 |
+
custom_css = """
|
70 |
+
<head>
|
71 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
72 |
+
</head>
|
73 |
+
"""
|
74 |
+
|
75 |
+
with gr.Blocks(css=custom_css) as iface:
|
76 |
+
gr.Markdown("# DeepFocus-X3")
|
77 |
+
with gr.Tab("Generate All"):
|
78 |
+
with gr.Row():
|
79 |
+
input_text = gr.Textbox(label="Input Text", placeholder="Enter your text here...", container=False)
|
80 |
+
output_text = gr.Textbox(label="Output", placeholder="Output will appear here...", container=False)
|
81 |
+
generate_button = gr.Button("Generate", container=False)
|
82 |
+
generate_button.click(fn=generate_all, inputs=input_text, outputs=output_text)
|
83 |
+
|
84 |
+
with gr.Tab("Logs"):
|
85 |
+
with gr.Row():
|
86 |
+
log_output = gr.Textbox(label="Logs", placeholder="Logs will appear here...", container=False)
|
87 |
+
report_button = gr.Button("Report using Logs", container=False)
|
88 |
+
report_button.click(fn=generate_report, outputs=log_output)
|
89 |
|
90 |
# Run and Push to HuggingFace
|
91 |
def run_and_push():
|
92 |
train_dataset()
|
93 |
+
try:
|
94 |
+
api = HfApi()
|
95 |
+
api.create_repo(repo_id=HF_REPO, private=False, exist_ok=True)
|
96 |
+
upload_file(
|
97 |
+
path_or_fileobj="output.csv",
|
98 |
+
path_in_repo="output.csv",
|
99 |
+
repo_id=HF_REPO
|
100 |
+
)
|
101 |
+
logging.info("Dataset pushed to HuggingFace.")
|
102 |
+
except Exception as e:
|
103 |
+
logging.error(f"Error uploading to HuggingFace: {e}")
|
104 |
+
try:
|
105 |
+
# Log the error to a separate errors repo
|
106 |
+
errors_repo = "katsukiai/errors"
|
107 |
+
api.create_repo(repo_id=errors_repo, private=False, exist_ok=True)
|
108 |
+
with open('upload_error.log', 'w') as error_file:
|
109 |
+
error_file.write(f"Error uploading to HuggingFace: {e}\n")
|
110 |
+
upload_file(
|
111 |
+
path_or_fileobj="upload_error.log",
|
112 |
+
path_in_repo="upload_error.log",
|
113 |
+
repo_id=errors_repo
|
114 |
+
)
|
115 |
+
logging.info("Error log pushed to HuggingFace errors repo.")
|
116 |
+
except Exception as e2:
|
117 |
+
logging.error(f"Failed to log error to HuggingFace errors repo: {e2}")
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
iface.launch()
|