Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,20 @@
|
|
1 |
-
# inference.py
|
2 |
-
|
3 |
from pptx import Presentation
|
4 |
import re
|
5 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def extract_text_from_pptx(file_path):
|
8 |
presentation = Presentation(file_path)
|
@@ -15,14 +27,10 @@ def extract_text_from_pptx(file_path):
|
|
15 |
|
16 |
return "\n".join(text)
|
17 |
|
18 |
-
def
|
19 |
-
file_path = "path/to/your/powerpoint.pptx" # Specify the path to your PowerPoint file
|
20 |
-
|
21 |
extracted_text = extract_text_from_pptx(file_path)
|
22 |
cleaned_text = re.sub(r'\s+', ' ', extracted_text)
|
23 |
|
24 |
-
print(cleaned_text)
|
25 |
-
|
26 |
classifier = pipeline("text-classification", model="Ahmed235/roberta_classification")
|
27 |
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
28 |
|
@@ -30,9 +38,22 @@ def main():
|
|
30 |
predicted_label = result['label']
|
31 |
predicted_probability = result['score']
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from pptx import Presentation
|
2 |
import re
|
3 |
from transformers import pipeline
|
4 |
+
import subprocess
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# Install necessary libraries
|
8 |
+
libraries = [
|
9 |
+
'transformers',
|
10 |
+
'gradio',
|
11 |
+
]
|
12 |
+
|
13 |
+
for library in libraries:
|
14 |
+
try:
|
15 |
+
subprocess.check_call(['pip', 'install', library])
|
16 |
+
except subprocess.CalledProcessError as e:
|
17 |
+
print(f"Error installing {library}: {e}")
|
18 |
|
19 |
def extract_text_from_pptx(file_path):
|
20 |
presentation = Presentation(file_path)
|
|
|
27 |
|
28 |
return "\n".join(text)
|
29 |
|
30 |
+
def predict_pptx_content(file_path):
|
|
|
|
|
31 |
extracted_text = extract_text_from_pptx(file_path)
|
32 |
cleaned_text = re.sub(r'\s+', ' ', extracted_text)
|
33 |
|
|
|
|
|
34 |
classifier = pipeline("text-classification", model="Ahmed235/roberta_classification")
|
35 |
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
36 |
|
|
|
38 |
predicted_label = result['label']
|
39 |
predicted_probability = result['score']
|
40 |
|
41 |
+
prediction = {
|
42 |
+
"Predicted Label": predicted_label,
|
43 |
+
"Evaluation": f"Evaluate the topic according to {predicted_label} is: {predicted_probability}",
|
44 |
+
"Summary": summarizer(cleaned_text, max_length=80, min_length=30, do_sample=False)
|
45 |
+
}
|
46 |
+
|
47 |
+
return prediction
|
48 |
+
|
49 |
+
# Define the Gradio interface
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=predict_pptx_content,
|
52 |
+
inputs=gr.File(type="file", label="Upload PowerPoint (.pptx) file"),
|
53 |
+
outputs=["text", "text", "text"], # Predicted Label, Evaluation, Summary
|
54 |
+
live=True,
|
55 |
+
title="<h1 style='color: lightgreen; text-align: center;'>PPTX Analyzer</h1>",
|
56 |
+
)
|
57 |
+
|
58 |
+
# Deploy the Gradio interface
|
59 |
+
iface.launch(share=True)
|