Spaces:
No application file
No application file
File size: 1,753 Bytes
916ac73 | 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 | 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 <class 'str'>
# 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) |