import gradio as gr import pickle from sklearn.feature_extraction.text import TfidfVectorizer import pandas as pd # def predict_text(text): # with open('model.pkl', 'rb') as file: # loaded_model, vectorizer = pickle.load(file) # vect_input=vectorizer.transform([text]) # # with open('model.pkl', 'rb') as file: # # loaded_model = pickle.load(file) # print("=== Model Loading ===", loaded_model) # text_label = loaded_model.predict(vect_input) # print(loaded_model.predict(vect_input)) # return text , "is" , text_label[0], "generated" # demo = gr.Interface(fn=predict_text, inputs="text", outputs="text") # demo.launch(share=True) import pickle import gradio as gr # Define the prediction function def predict_text(text): # Load the model and vectorizer with open('model.pkl', 'rb') as file: loaded_model, vectorizer = pickle.load(file) # Transform the input text using the loaded vectorizer vect_input = vectorizer.transform([text]) # Make predictions using the loaded model text_label = loaded_model.predict(vect_input) # Return the prediction result if text_label[0] == "chatgpt": result = "AI-generated text" else: result = "Human-written text" return f"The text you entered is: {result}" # Build a simple Gradio interface demo = gr.Interface( fn=predict_text, # Function to call for predictions inputs=gr.Textbox(lines=5, placeholder="Enter your text here..."), # Input textbox for the text outputs="text", # Output as a text label title="AI vs Human Text Classifier", # Title of the interface description="Enter a piece of text to find out if it was written by AI or a human.", # Description theme="compact", # Gradio theme for simplicity #live=True # Make it live without refreshing ) # Launch the interface demo.launch(share=True)