File size: 1,124 Bytes
20adaed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import lightgbm as lgb
import joblib

# Load your trained model (assuming it's saved as 'lgbm_model.pkl')
model = joblib.load('lgbm_model.pkl')

def classify_text(text):
    # Convert the input text to the appropriate format for your model
    # For simplicity, let's assume you have a function `preprocess_text` for this
    # processed_text = preprocess_text(text)
    
    # If your model expects numerical features, convert text to numerical features
    # For example:
    # features = text_to_features(processed_text)
    
    # Here, we assume the model can take raw text directly for simplicity
    prediction = model.predict([text])
    
    return int(prediction[0])

# Create the Gradio interface
iface = gr.Interface(
    fn=classify_text,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
    outputs=gr.outputs.Label(num_top_classes=1),
    title="Fake News Classifier",
    description="Enter text to classify if it's fake (1) or not fake (0).",
    examples=["This is a sample news article."]
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()