Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,14 @@ from deep_translator import GoogleTranslator
|
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
|
| 8 |
@st.cache_resource
|
| 9 |
-
def text_summary(text, maxlength=None):
|
| 10 |
translatedtext = GoogleTranslator(source='auto', target='en').translate(text)
|
| 11 |
#create summary instance
|
| 12 |
summary = Summary()
|
| 13 |
text = (text)
|
| 14 |
result = summary(text)
|
|
|
|
|
|
|
| 15 |
return result
|
| 16 |
|
| 17 |
def extract_text_from_pdf(file_path):
|
|
@@ -23,6 +25,7 @@ def extract_text_from_pdf(file_path):
|
|
| 23 |
return text
|
| 24 |
|
| 25 |
choice = st.sidebar.selectbox("Select your choice", ["Summarize Text", "Summarize Document"])
|
|
|
|
| 26 |
|
| 27 |
if choice == "Summarize Text":
|
| 28 |
st.subheader("Summarize Text using txtai")
|
|
@@ -35,7 +38,7 @@ if choice == "Summarize Text":
|
|
| 35 |
st.info(input_text)
|
| 36 |
with col2:
|
| 37 |
st.markdown("**Summary Result**")
|
| 38 |
-
result = text_summary(input_text)
|
| 39 |
st.success(result)
|
| 40 |
|
| 41 |
elif choice == "Summarize Document":
|
|
@@ -54,6 +57,6 @@ elif choice == "Summarize Document":
|
|
| 54 |
with col2:
|
| 55 |
st.markdown("**Summary Result**")
|
| 56 |
text = extract_text_from_pdf("doc_file.pdf")
|
| 57 |
-
doc_summary = text_summary(text)
|
| 58 |
st.success(doc_summary)
|
| 59 |
|
|
|
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
|
| 8 |
@st.cache_resource
|
| 9 |
+
def text_summary(text, translate_fa, maxlength=None):
|
| 10 |
translatedtext = GoogleTranslator(source='auto', target='en').translate(text)
|
| 11 |
#create summary instance
|
| 12 |
summary = Summary()
|
| 13 |
text = (text)
|
| 14 |
result = summary(text)
|
| 15 |
+
if translate_fa:
|
| 16 |
+
result = GoogleTranslator(source='auto', target='en').translate(result)
|
| 17 |
return result
|
| 18 |
|
| 19 |
def extract_text_from_pdf(file_path):
|
|
|
|
| 25 |
return text
|
| 26 |
|
| 27 |
choice = st.sidebar.selectbox("Select your choice", ["Summarize Text", "Summarize Document"])
|
| 28 |
+
translate_fa = st.toggle('Translate to Persian')
|
| 29 |
|
| 30 |
if choice == "Summarize Text":
|
| 31 |
st.subheader("Summarize Text using txtai")
|
|
|
|
| 38 |
st.info(input_text)
|
| 39 |
with col2:
|
| 40 |
st.markdown("**Summary Result**")
|
| 41 |
+
result = text_summary(input_text, translate_fa)
|
| 42 |
st.success(result)
|
| 43 |
|
| 44 |
elif choice == "Summarize Document":
|
|
|
|
| 57 |
with col2:
|
| 58 |
st.markdown("**Summary Result**")
|
| 59 |
text = extract_text_from_pdf("doc_file.pdf")
|
| 60 |
+
doc_summary = text_summary(text, translate_fa)
|
| 61 |
st.success(doc_summary)
|
| 62 |
|