Update app.py
Browse files
app.py
CHANGED
@@ -57,21 +57,35 @@ def split_text(text, max_tokens=1024):
|
|
57 |
# Helper function to summarize text
|
58 |
def summarize_text(text):
|
59 |
chunks = split_text(text)
|
60 |
-
summaries = [
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
return " ".join(summaries)
|
62 |
|
63 |
# Helper function to translate text
|
64 |
def translate_text(text, language):
|
65 |
translator = get_translator(language)
|
66 |
if translator:
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
return text
|
70 |
|
71 |
def process_text(input_text, language):
|
|
|
72 |
summary = summarize_text(input_text)
|
|
|
73 |
bullet_points = generate_bullet_points(summary)
|
|
|
74 |
translated_text = translate_text(bullet_points, language)
|
|
|
75 |
return bullet_points, translated_text
|
76 |
|
77 |
# Create Gradio interface
|
|
|
57 |
# Helper function to summarize text
|
58 |
def summarize_text(text):
|
59 |
chunks = split_text(text)
|
60 |
+
summaries = []
|
61 |
+
for chunk in chunks:
|
62 |
+
try:
|
63 |
+
summary = summarizer(chunk, max_length=150, min_length=40, do_sample=False)[0]['summary_text']
|
64 |
+
summaries.append(summary)
|
65 |
+
except Exception as e:
|
66 |
+
print(f"Error summarizing chunk: {chunk}\nError: {e}")
|
67 |
return " ".join(summaries)
|
68 |
|
69 |
# Helper function to translate text
|
70 |
def translate_text(text, language):
|
71 |
translator = get_translator(language)
|
72 |
if translator:
|
73 |
+
try:
|
74 |
+
translated_text = translator(text)[0]['translation_text']
|
75 |
+
return translated_text
|
76 |
+
except Exception as e:
|
77 |
+
print(f"Error translating text: {text}\nError: {e}")
|
78 |
+
return text
|
79 |
return text
|
80 |
|
81 |
def process_text(input_text, language):
|
82 |
+
print(f"Input text: {input_text[:500]}...") # Show only the first 500 characters for brevity
|
83 |
summary = summarize_text(input_text)
|
84 |
+
print(f"Summary: {summary[:500]}...") # Show only the first 500 characters for brevity
|
85 |
bullet_points = generate_bullet_points(summary)
|
86 |
+
print(f"Bullet Points: {bullet_points}")
|
87 |
translated_text = translate_text(bullet_points, language)
|
88 |
+
print(f"Translated Text: {translated_text}")
|
89 |
return bullet_points, translated_text
|
90 |
|
91 |
# Create Gradio interface
|