Spaces:
Runtime error
Runtime error
Update main .py
Browse files
main .py
CHANGED
|
@@ -32,9 +32,14 @@ from gtts import gTTS
|
|
| 32 |
from reportlab.lib.pagesizes import letter
|
| 33 |
from reportlab.pdfgen import canvas
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
nltk.
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Check GPU availability
|
| 40 |
print("Checking GPU availability...")
|
|
@@ -44,9 +49,14 @@ if torch.cuda.is_available():
|
|
| 44 |
else:
|
| 45 |
print("Device set to use CPU")
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Initialize SQLite database
|
| 48 |
def init_sqlite_db():
|
| 49 |
-
os.makedirs('/data', exist_ok=True)
|
| 50 |
if not os.access('/data', os.W_OK):
|
| 51 |
raise PermissionError("No write permission for /data directory")
|
| 52 |
conn = sqlite3.connect('/data/vernacular_learning.db')
|
|
@@ -118,9 +128,6 @@ def init_sqlite_db():
|
|
| 118 |
conn.commit()
|
| 119 |
return conn
|
| 120 |
|
| 121 |
-
# Create file storage directory
|
| 122 |
-
os.makedirs('/content/files', exist_ok=True)
|
| 123 |
-
|
| 124 |
# Define supported languages
|
| 125 |
SUPPORTED_LANGUAGES = {
|
| 126 |
"Hindi": "hi",
|
|
@@ -428,6 +435,20 @@ def get_forum_messages():
|
|
| 428 |
conn.close()
|
| 429 |
return messages
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
def create_gradio_interface():
|
| 432 |
with gr.Blocks(theme='default') as interface:
|
| 433 |
gr.Markdown("# π Vernacular Learning Platform")
|
|
@@ -511,20 +532,6 @@ def create_gradio_interface():
|
|
| 511 |
store_content(source, translated_text, language, category, subcategory)
|
| 512 |
return f"Content processed:\nSummary: {summary}\nStored in database."
|
| 513 |
|
| 514 |
-
def generate_content_tts(content_output, language):
|
| 515 |
-
if not content_output or "Error" in content_output:
|
| 516 |
-
return None
|
| 517 |
-
summary = content_output.split("Summary: ")[-1].split("\n")[0]
|
| 518 |
-
output_file = f"/content/files/tts_{uuid.uuid4()}.mp3"
|
| 519 |
-
lang_code = SUPPORTED_LANGUAGES.get(language, 'en')
|
| 520 |
-
return generate_tts(summary, lang_code, output_file)
|
| 521 |
-
|
| 522 |
-
def download_content(content_output):
|
| 523 |
-
if not content_output or "Error" in content_output:
|
| 524 |
-
return None
|
| 525 |
-
output_file = f"/content/files/content_{uuid.uuid4()}.pdf"
|
| 526 |
-
return generate_pdf(content_output, output_file)
|
| 527 |
-
|
| 528 |
process_button.click(
|
| 529 |
fn=process_content,
|
| 530 |
inputs=[content_type, pdf_input, url_input, language, category, subcategory],
|
|
|
|
| 32 |
from reportlab.lib.pagesizes import letter
|
| 33 |
from reportlab.pdfgen import canvas
|
| 34 |
|
| 35 |
+
# Set NLTK data path to persistent storage
|
| 36 |
+
nltk.data.path.append('/data/nltk_data')
|
| 37 |
+
# Download NLTK resources if not already present
|
| 38 |
+
try:
|
| 39 |
+
nltk.download('punkt', download_dir='/data/nltk_data')
|
| 40 |
+
nltk.download('stopwords', download_dir='/data/nltk_data')
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"Failed to download NLTK data: {e}")
|
| 43 |
|
| 44 |
# Check GPU availability
|
| 45 |
print("Checking GPU availability...")
|
|
|
|
| 49 |
else:
|
| 50 |
print("Device set to use CPU")
|
| 51 |
|
| 52 |
+
# Create file storage directory
|
| 53 |
+
os.makedirs('/data/files', exist_ok=True)
|
| 54 |
+
if not os.access('/data/files', os.W_OK):
|
| 55 |
+
raise PermissionError("No write permission for /data/files directory")
|
| 56 |
+
|
| 57 |
# Initialize SQLite database
|
| 58 |
def init_sqlite_db():
|
| 59 |
+
os.makedirs('/data', exist_ok=True)
|
| 60 |
if not os.access('/data', os.W_OK):
|
| 61 |
raise PermissionError("No write permission for /data directory")
|
| 62 |
conn = sqlite3.connect('/data/vernacular_learning.db')
|
|
|
|
| 128 |
conn.commit()
|
| 129 |
return conn
|
| 130 |
|
|
|
|
|
|
|
|
|
|
| 131 |
# Define supported languages
|
| 132 |
SUPPORTED_LANGUAGES = {
|
| 133 |
"Hindi": "hi",
|
|
|
|
| 435 |
conn.close()
|
| 436 |
return messages
|
| 437 |
|
| 438 |
+
def generate_content_tts(content_output, language):
|
| 439 |
+
if not content_output or "Error" in content_output:
|
| 440 |
+
return None
|
| 441 |
+
summary = content_output.split("Summary: ")[-1].split("\n")[0]
|
| 442 |
+
output_file = f"/data/files/tts_{uuid.uuid4()}.mp3"
|
| 443 |
+
lang_code = SUPPORTED_LANGUAGES.get(language, 'en')
|
| 444 |
+
return generate_tts(summary, lang_code, output_file)
|
| 445 |
+
|
| 446 |
+
def download_content(content_output):
|
| 447 |
+
if not content_output or "Error" in content_output:
|
| 448 |
+
return None
|
| 449 |
+
output_file = f"/data/files/content_{uuid.uuid4()}.pdf"
|
| 450 |
+
return generate_pdf(content_output, output_file)
|
| 451 |
+
|
| 452 |
def create_gradio_interface():
|
| 453 |
with gr.Blocks(theme='default') as interface:
|
| 454 |
gr.Markdown("# π Vernacular Learning Platform")
|
|
|
|
| 532 |
store_content(source, translated_text, language, category, subcategory)
|
| 533 |
return f"Content processed:\nSummary: {summary}\nStored in database."
|
| 534 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
process_button.click(
|
| 536 |
fn=process_content,
|
| 537 |
inputs=[content_type, pdf_input, url_input, language, category, subcategory],
|