Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
import logging
|
4 |
-
from PyPDF2 import PdfReader
|
5 |
|
6 |
# Setup logging
|
7 |
def setup_logging():
|
@@ -13,73 +12,32 @@ def setup_logging():
|
|
13 |
]
|
14 |
)
|
15 |
|
16 |
-
# Function to extract text from a PDF file
|
17 |
-
def extract_text_from_pdf(pdf_file):
|
18 |
-
pdf_reader = PdfReader(pdf_file)
|
19 |
-
text = ""
|
20 |
-
for page in pdf_reader.pages:
|
21 |
-
text += page.extract_text()
|
22 |
-
return text
|
23 |
-
|
24 |
def main():
|
25 |
setup_logging()
|
26 |
logging.info("Starting the Streamlit app.")
|
27 |
|
28 |
-
# Initialize the
|
29 |
-
|
30 |
|
31 |
# Streamlit UI
|
32 |
-
st.title("
|
33 |
-
st.write("
|
34 |
-
|
35 |
-
input_type = st.radio(
|
36 |
-
"Select Input Type:",
|
37 |
-
options=["Text", "Text File", "PDF", "DOCX", "Audio"],
|
38 |
-
index=0
|
39 |
-
)
|
40 |
|
41 |
-
|
42 |
-
text = None
|
43 |
-
audio = None
|
44 |
|
45 |
-
if
|
46 |
-
text = st.text_area("Enter your text here:", placeholder="Type your text here...")
|
47 |
-
elif input_type == "Text File":
|
48 |
-
file = st.file_uploader("Upload your text file:", type=["txt"])
|
49 |
-
elif input_type == "PDF":
|
50 |
-
file = st.file_uploader("Upload your PDF file:", type=["pdf"])
|
51 |
-
elif input_type == "DOCX":
|
52 |
-
file = st.file_uploader("Upload your DOCX file:", type=["docx"])
|
53 |
-
elif input_type == "Audio":
|
54 |
-
audio = st.file_uploader("Upload your audio file:", type=["wav", "mp3", "m4a"])
|
55 |
-
|
56 |
-
if st.button("Report Result"):
|
57 |
try:
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
logging.info(f"Processing text file: {file.name}")
|
65 |
-
text = file.read().decode("utf-8") # Assuming UTF-8 encoding
|
66 |
-
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
67 |
-
elif input_type == "PDF" and file:
|
68 |
-
logging.info(f"Processing PDF file: {file.name}")
|
69 |
-
text = extract_text_from_pdf(file)
|
70 |
-
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
71 |
-
elif input_type == "Audio" and audio:
|
72 |
-
logging.info("Processing audio input.")
|
73 |
-
# Add audio processing logic here
|
74 |
-
summary = "Audio processing not implemented yet."
|
75 |
else:
|
76 |
-
|
77 |
-
logging.warning("Invalid input type provided.")
|
78 |
-
|
79 |
-
st.text_area("Report Result:", summary[0]['summary_text'] if isinstance(summary, list) else summary, height=200)
|
80 |
except Exception as e:
|
81 |
-
logging.error(f"Error during
|
82 |
-
st.error("An error occurred during
|
83 |
|
84 |
logging.info("Closing the Streamlit app.")
|
85 |
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
import logging
|
|
|
4 |
|
5 |
# Setup logging
|
6 |
def setup_logging():
|
|
|
12 |
]
|
13 |
)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def main():
|
16 |
setup_logging()
|
17 |
logging.info("Starting the Streamlit app.")
|
18 |
|
19 |
+
# Initialize the translation pipeline for English to Hinglish
|
20 |
+
translator = pipeline("translation", model="surajp/eng_to_hinglish") # Replace with your desired model
|
21 |
|
22 |
# Streamlit UI
|
23 |
+
st.title("English to Hinglish Translator")
|
24 |
+
st.write("Type or paste your English text below, and get the Hinglish translation.")
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
text = st.text_area("Enter your English text here:", placeholder="Type here...")
|
|
|
|
|
27 |
|
28 |
+
if st.button("Translate"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
try:
|
30 |
+
if text:
|
31 |
+
logging.info("Translating English text to Hinglish.")
|
32 |
+
result = translator(text, max_length=200)
|
33 |
+
translation = result[0]['translation_text'] if result else "No translation available."
|
34 |
+
st.text_area("Hinglish Translation:", translation, height=200)
|
35 |
+
logging.info("Translation completed successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
else:
|
37 |
+
st.warning("Please enter text to translate.")
|
|
|
|
|
|
|
38 |
except Exception as e:
|
39 |
+
logging.error(f"Error during translation: {e}")
|
40 |
+
st.error("An error occurred during translation. Please check the logs for more details.")
|
41 |
|
42 |
logging.info("Closing the Streamlit app.")
|
43 |
|