ink85 commited on
Commit
31a2d49
·
verified ·
1 Parent(s): 2709ca0

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +6 -26
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,27 +1,5 @@
1
- import os
2
-
3
- # Use /tmp (always writable in Hugging Face Spaces & Docker)
4
- os.environ["HF_HOME"] = "/tmp/huggingface"
5
- os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
6
- os.environ["HF_HUB_CACHE"] = "/tmp/hfhub"
7
-
8
- # Create directories if not exist
9
- os.makedirs(os.environ["HF_HOME"], exist_ok=True)
10
- os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)
11
- os.makedirs(os.environ["HF_HUB_CACHE"], exist_ok=True)
12
-
13
-
14
- # Redirect Hugging Face cache to writable directory
15
- # os.environ["HF_HOME"] = "/app/.cache/huggingface"
16
- # os.environ["TRANSFORMERS_CACHE"] = "/app/.cache/transformers"
17
- # os.environ["HF_HUB_CACHE"] = "/app/.cache/hub"
18
-
19
- # Make sure the folders exist
20
- # os.makedirs(os.environ["HF_HOME"], exist_ok=True)
21
- # os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)
22
- # os.makedirs(os.environ["HF_HUB_CACHE"], exist_ok=True)
23
-
24
  import streamlit as st
 
25
  import json
26
  import re
27
  import fitz # PyMuPDF
@@ -49,11 +27,12 @@ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
49
 
50
  # -------------------------
51
  # Extract text from PDF
52
- # -------------------------
 
53
  def extract_text_from_pdf(pdf_file):
54
  text = ""
55
- # Save the uploaded file temporarily to process it with fitz
56
- temp_file_path = "temp.pdf"
57
  with open(temp_file_path, "wb") as f:
58
  f.write(pdf_file.getvalue())
59
 
@@ -68,6 +47,7 @@ def extract_text_from_pdf(pdf_file):
68
 
69
  return text.strip()
70
 
 
71
  # Translate text to English using Google Translate
72
  # -------------------------
73
  def translate_text_google(text):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import os
3
  import json
4
  import re
5
  import fitz # PyMuPDF
 
27
 
28
  # -------------------------
29
  # Extract text from PDF
30
+ # ------------------------
31
+
32
  def extract_text_from_pdf(pdf_file):
33
  text = ""
34
+ # Save the uploaded file into /tmp (writable in Spaces/Docker)
35
+ temp_file_path = os.path.join("/tmp", "temp.pdf")
36
  with open(temp_file_path, "wb") as f:
37
  f.write(pdf_file.getvalue())
38
 
 
47
 
48
  return text.strip()
49
 
50
+
51
  # Translate text to English using Google Translate
52
  # -------------------------
53
  def translate_text_google(text):
requirements.txt CHANGED
@@ -2,6 +2,6 @@ streamlit==1.43.2
2
  PyMuPDF==1.26.4
3
  langdetect==1.0.9
4
  googletrans==4.0.0-rc1
5
- transformers>=4.44.2
6
  joblib==1.4.2
7
  torch==2.8.0
 
2
  PyMuPDF==1.26.4
3
  langdetect==1.0.9
4
  googletrans==4.0.0-rc1
5
+ transformers==4.46.3
6
  joblib==1.4.2
7
  torch==2.8.0