Spaces:
Running
Running
TeacherPuffy
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
import zipfile
|
5 |
-
from datasets import Dataset
|
6 |
from huggingface_hub import HfApi
|
7 |
import logging
|
8 |
import time # Import time module for adding delays
|
@@ -69,6 +68,9 @@ def process_text(file, prompt):
|
|
69 |
if not hf_api.token:
|
70 |
raise ValueError("Hugging Face token not found in environment variables.")
|
71 |
|
|
|
|
|
|
|
72 |
# Process each chunk with a 20-second delay between API calls
|
73 |
results = []
|
74 |
for idx, chunk in enumerate(chunks):
|
@@ -86,11 +88,15 @@ def process_text(file, prompt):
|
|
86 |
f.write(result)
|
87 |
logger.info(f"Saved result to {output_file}")
|
88 |
|
89 |
-
# Upload the chunk to Hugging Face
|
90 |
try:
|
91 |
logger.info(f"Uploading chunk {idx + 1} to Hugging Face...")
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
logger.info(f"Chunk {idx + 1} uploaded to Hugging Face successfully.")
|
95 |
except Exception as e:
|
96 |
logger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")
|
|
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
import zipfile
|
|
|
5 |
from huggingface_hub import HfApi
|
6 |
import logging
|
7 |
import time # Import time module for adding delays
|
|
|
68 |
if not hf_api.token:
|
69 |
raise ValueError("Hugging Face token not found in environment variables.")
|
70 |
|
71 |
+
# Repository name on Hugging Face Hub
|
72 |
+
repo_name = "TeacherPuffy/book"
|
73 |
+
|
74 |
# Process each chunk with a 20-second delay between API calls
|
75 |
results = []
|
76 |
for idx, chunk in enumerate(chunks):
|
|
|
88 |
f.write(result)
|
89 |
logger.info(f"Saved result to {output_file}")
|
90 |
|
91 |
+
# Upload the chunk as an individual text file to Hugging Face
|
92 |
try:
|
93 |
logger.info(f"Uploading chunk {idx + 1} to Hugging Face...")
|
94 |
+
hf_api.upload_file(
|
95 |
+
path_or_fileobj=output_file,
|
96 |
+
path_in_repo=f"output_{idx}.txt", # File name in the repository
|
97 |
+
repo_id=repo_name,
|
98 |
+
repo_type="dataset",
|
99 |
+
)
|
100 |
logger.info(f"Chunk {idx + 1} uploaded to Hugging Face successfully.")
|
101 |
except Exception as e:
|
102 |
logger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")
|