from pptx import Presentation import re from transformers import pipeline 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) print(f"Extracted text: {extracted_text}") cleaned_text = re.sub(r'\s+', ' ', extracted_text) print(f"Cleaned text: {cleaned_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)} # 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="

PPTX Analyzer

", ) # Deploy the Gradio interface iface.launch