RyhanSunny commited on
Commit
7dfdb33
1 Parent(s): fd4059c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -40,25 +40,31 @@ def get_summarizer(language):
40
 
41
  # Gradio interface function to summarize the document
42
  def summarize_document(file_info):
43
- # Read the uploaded file and extract text
44
- file_path = file_info["name"]
45
- text = read_document(file_path)
46
-
47
- if not text.strip():
48
- return "The document is empty or could not be read."
49
-
50
- # Detect the language of the text
51
- language = detect_language(text)
52
- if not language:
53
- return "Language detection failed."
54
 
55
- # Get the appropriate summarizer model
56
- summarizer = get_summarizer(language)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- # Generate summary
59
- summary = summarizer(text, max_length=130, min_length=30, truncation=True)
60
- return summary[0]['summary_text']
61
-
62
  # Gradio app interface
63
  iface = gr.Interface(
64
  fn=summarize_document,
 
40
 
41
  # Gradio interface function to summarize the document
42
  def summarize_document(file_info):
43
+ try:
44
+ # Read the uploaded file and extract text
45
+ file_path = file_info["name"]
46
+ text = read_document(file_path)
47
+
48
+ if not text.strip():
49
+ return "The document is empty or could not be read."
 
 
 
 
50
 
51
+ # Detect the language of the text
52
+ language = detect_language(text)
53
+ if not language:
54
+ return "Language detection failed."
55
+
56
+ # Get the appropriate summarizer model
57
+ summarizer = get_summarizer(language)
58
+
59
+ # Generate summary
60
+ summary = summarizer(text, max_length=130, min_length=30, truncation=True)
61
+ return summary[0]['summary_text']
62
+ except Exception as e:
63
+ # This will print the error message and the traceback
64
+ print(f"An error occurred: {e}")
65
+ traceback.print_exc()
66
+ return str(e) # Return the error message as output to the user
67
 
 
 
 
 
68
  # Gradio app interface
69
  iface = gr.Interface(
70
  fn=summarize_document,