Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
# Define the Gradio interface
|
66 |
interface = gr.Interface(
|
67 |
fn=analyze_and_complete,
|
68 |
-
inputs=gr.File(file_count="
|
69 |
outputs=["text", "text", "text", "text"],
|
70 |
title="Movie Script Analyzer and Completer",
|
71 |
-
description="Upload
|
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__":
|