import gradio as gr from transformers import pipeline # Create a text classification pipeline classifier = pipeline("text-classification", model="Ahmed235/roberta_classification", tokenizer="Ahmed235/roberta_classification") 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): try: extracted_text = extract_text_from_pptx(file_path) # Perform inference using the pipeline result = classifier(extracted_text) predicted_label = result[0]['label'] predicted_probability = result[0]['score'] prediction = { "Predicted Label": predicted_label, "Evaluation": f"Evaluate the topic according to {predicted_label} is: {predicted_probability}", } return prediction except Exception as e: # Log the error details print(f"Error in predict_pptx_content: {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"], # Predicted Label, Evaluation live=False, # Change to True for one-time analysis title="