File size: 2,381 Bytes
44e21a6
 
 
 
 
 
2bb61b8
 
 
 
 
 
 
 
 
 
 
12b0ed7
1aa90a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb61b8
 
7de2d0b
2bb61b8
 
 
 
 
12b0ed7
 
7de2d0b
 
12b0ed7
 
 
 
 
 
 
e2d35e8
7de2d0b
cf38445
12b0ed7
 
 
 
5fe069a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from pptx import Presentation
import re
from transformers import pipeline
import subprocess
import gradio as gr

def extract_text_from_pptx(file_path):
    presentation = Presentation(file_path)

    text = []
    for slide_number, slide in enumerate(presentation.slides, start=1):
        for shape in slide.shapes:
            if hasattr(shape, "text"):
                text.append(shape.text)

    return "\n".join(text)

def predict_pptx_content(file_path):
    print(f"File path received: {file_path}")
    try:
        extracted_text = extract_text_from_pptx(file_path)
        cleaned_text = re.sub(r'\s+', ' ', extracted_text)

        classifier = pipeline("text-classification", model="Ahmed235/roberta_classification")
        #summarizer = pipeline("summarization", model="Falconsai/text_summarization")

        result = classifier(cleaned_text)[0]
        predicted_label = result['label']
        predicted_probability = result['score']

        prediction = {
            "Predicted Label": predicted_label,
            "Evaluation": f"Evaluate the topic according to {predicted_label} is: {predicted_probability}"
            #"Summary": summarizer(cleaned_text, max_length=80, min_length=30, do_sample=False)
        }

        return prediction
    except Exception as e:
        print(f"Error processing file: {e}")
        return {"error": str(e)}


    classifier = pipeline("text-classification", model="Ahmed235/roberta_classification")
    #summarizer = pipeline("summarization", model="Falconsai/text_summarization")

    result = classifier(cleaned_text)[0]
    predicted_label = result['label']
    predicted_probability = result['score']

    prediction = {
        "Predicted Label": predicted_label,
        "Evaluation": f"Evaluate the topic according to {predicted_label} is: {predicted_probability}"
        #"Summary": summarizer(cleaned_text, max_length=80, min_length=30, do_sample=False)
    }

    return prediction

# Define the Gradio interface
iface = gr.Interface(
    fn=predict_pptx_content,
    inputs=gr.File(type="filepath", label="Upload PowerPoint (.pptx) file"),
    outputs=["text", "text"],  # Predicted Label, Evaluation, Summary
    live=False,  # Change to False for one-time analysis
    title="<h1 style='color: lightgreen; text-align: center;'>PPTX Analyzer</h1>",
)

# Deploy the Gradio interface
iface.launch(share=True)