Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the GPT-2 pipeline for text generation | |
| classifier = pipeline("text-classification", model="gpt2") | |
| def analyze_text(text): | |
| # Use the GPT-2 classifier to predict if the text is fake or true | |
| result = classifier(text)[0] | |
| # Extract the label and confidence score | |
| label = result['label'] | |
| score = result['score'] * 100 | |
| # Beautify the output | |
| if label == 'LABEL_0': | |
| result_text = "This text is likely fake." | |
| else: | |
| result_text = "This text is likely true." | |
| return {"Prediction": result_text, "Confidence (%)": f"{score:.2f}"} | |
| # Gradio interface with soft theme, title, description, input examples, and output labels | |
| gr.Interface(analyze_text, | |
| inputs=[gr.Textbox(label="Text", placeholder="Enter text here")], | |
| outputs="text", | |
| title="Fake vs. True Text Analyzer", | |
| description="Enter a piece of text to analyze whether it is likely fake or true.", | |
| examples=["Elon Musk is rich person", "Moon was discovered in 1908 by Cristiano Ronaldo"], | |
| theme="soft" | |
| ).launch() | |