import gradio as gr import pandas as pd from data_loading import DataLoading from pre_processing import PreProcess from feature_engineering_cosine import FeatureCosine from recommendation import Recommendation class GradioApp: def __init__(self): # Initialize components self.dataLoad = DataLoading() self.preprocess = PreProcess() self.feature_engineering_cosine = FeatureCosine() self.recommendation = Recommendation() def applying_functions(self): data = self.preprocess.pre_processing() if data is None or not isinstance(data, pd.DataFrame): return "Error: Data not found!" tfidf_matrix, vectorizer = self.feature_engineering_cosine.compute_matrix(data) return data, tfidf_matrix, vectorizer def get_recommendation_book(self, book_title): # Apply necessary functions # print(f"Received book title type: {type(book_title)}") # Should be # print(f"Received book title: {book_title}") data, tfidf_matrix, vectorizer = self.applying_functions() # Ensure that tfidf_matrix and data are returned correctly if isinstance(data, str): # In case there's an error in fetching data return data # Get recommendations using the provided title recommendations = self.recommendation.get_recommendations(book_title, data, tfidf_matrix, vectorizer) return recommendations # Create Gradio interface for book recommendation def recommend_books(book_title): app = GradioApp() return app.get_recommendation_book(book_title) iface = gr.Interface(fn=recommend_books, inputs="text", outputs="text", title="Book Recommender System") iface.launch(share=True)