mohamedrady commited on
Commit
7b4a700
ยท
verified ยท
1 Parent(s): c3d42ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -18
app.py CHANGED
@@ -45,30 +45,33 @@ def extract_pdf_text(file_path):
45
  text += page.extract_text()
46
  return text
47
 
48
- def analyze_and_complete(file_path):
49
- if file_path.endswith(".pdf"):
50
- text = extract_pdf_text(file_path)
51
- else:
52
- with open(file_path, "r", encoding="utf-8") as file:
53
- text = file.read()
54
-
55
- output_directory = "/Users/Home/Library/Mobile Documents/com~apple~CloudDocs/osa/ุณูŠู†ุงุฑูŠูˆู‡ุงุช/ู„ูŠุงู„ูŠ ุงู”ู„ู ู„ูŠู„ุฉ"
56
- filename_prefix = os.path.splitext(os.path.basename(file_path))[0]
57
-
58
- spacy_entities = spacy_ner_analysis(text)
59
- sentences = nltk_extract_sentences(text)
60
- quotes = nltk_extract_quotes(text)
61
- token_count = count_tokens(text)
62
-
63
- return str(spacy_entities), "\n".join(sentences), "\n".join(quotes), str(token_count)
 
 
 
64
 
65
  # Define the Gradio interface
66
  interface = gr.Interface(
67
  fn=analyze_and_complete,
68
- inputs=gr.File(file_count="single", type="filepath"),
69
  outputs=["text", "text", "text", "text"],
70
  title="Movie Script Analyzer and Completer",
71
- description="Upload a text, PDF, or DOCX file to analyze and complete the movie script."
72
  )
73
 
74
  if __name__ == "__main__":
 
45
  text += page.extract_text()
46
  return text
47
 
48
+ def analyze_and_complete(file_paths):
49
+ results = []
50
+ for file_path in file_paths:
51
+ if file_path.endswith(".pdf"):
52
+ text = extract_pdf_text(file_path)
53
+ else:
54
+ with open(file_path, "r", encoding="utf-8") as file:
55
+ text = file.read()
56
+
57
+ output_directory = "/Users/Home/Library/Mobile Documents/com~apple~CloudDocs/osa/ุณูŠู†ุงุฑูŠูˆู‡ุงุช/ู„ูŠุงู„ูŠ ุงู”ู„ู ู„ูŠู„ุฉ"
58
+ filename_prefix = os.path.splitext(os.path.basename(file_path))[0]
59
+
60
+ spacy_entities = spacy_ner_analysis(text)
61
+ sentences = nltk_extract_sentences(text)
62
+ quotes = nltk_extract_quotes(text)
63
+ token_count = count_tokens(text)
64
+
65
+ results.append((str(spacy_entities), "\n".join(sentences), "\n".join(quotes), str(token_count)))
66
+ return results
67
 
68
  # Define the Gradio interface
69
  interface = gr.Interface(
70
  fn=analyze_and_complete,
71
+ inputs=gr.File(file_count="multiple", type="filepath"),
72
  outputs=["text", "text", "text", "text"],
73
  title="Movie Script Analyzer and Completer",
74
+ description="Upload text, PDF, or DOCX files to analyze and complete the movie script."
75
  )
76
 
77
  if __name__ == "__main__":