Spaces:
Sleeping
Sleeping
File size: 1,173 Bytes
8e9c493 4b74a37 8e9c493 4b74a37 8e9c493 4b74a37 8e9c493 4b74a37 7f38208 8e9c493 7f38208 8e9c493 7f38208 4b74a37 d01124e 7f38208 4b74a37 |
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 |
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()
|