Pratik3003/Text_Detection_AI_VS_Human
0
1import gradio as gr2import pickle3 4# Load the saved components5with open('tfidf_vectorizer.pkl', 'rb') as f:6 loaded_tfidf = pickle.load(f)7 8with open('truncated_svd.pkl', 'rb') as f:9 loaded_svd = pickle.load(f)10 11with open('svc.pkl', 'rb') as f:12 loaded_model = pickle.load(f)13 14# Function to preprocess text using TF-IDF and SVD, and make prediction15def preprocess_and_predict(text):16 # Vectorize input text using TF-IDF17 text_tfidf = loaded_tfidf.transform([text])18 19 # Reduce dimensionality using SVD20 text_svd = loaded_svd.transform(text_tfidf)21 22 # Predict using the SVC model23 prediction_result = loaded_model.predict(text_svd)24 25 # Return prediction result26 return prediction_result[0]27 28# Define the Gradio interface29iface = gr.Interface(30 fn=preprocess_and_predict, 31 inputs=gr.Textbox(label="Enter the text", placeholder="Type your text here..."),32 outputs=gr.Text(label="Prediction result"),33 title="Battle of Texts: AI vs Human Text Detection",34 description="Enter a text to determine if it is generated by AI or written by a human.",35 theme="dark"36)37 38# Launch the Gradio app39if __name__ == "__main__":40 iface.launch(share=True)41 42 