Download app.py from pravjet/streamlit: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/pravjet/streamlit/resolve/main/app.py
- Command line
-
hf download hf://spaces/pravjet/streamlit/app.py
-
curl -L -o app.py https://huggingface.co/spaces/pravjet/streamlit/resolve/main/app.py
1.71 kB
| import gradio as gr | |
| from transformers import pipeline | |
| from newspaper import Article | |
| # Load the model | |
| model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection") | |
| def analyze(input_text, input_type): | |
| # Auto-detect if input is URL or text | |
| if input_type == "Auto Detect": | |
| if input_text.startswith("http://") or input_text.startswith("https://"): | |
| input_type = "URL" | |
| else: | |
| input_type = "Text" | |
| if input_type == "URL": | |
| try: | |
| article = Article(input_text) | |
| article.download() | |
| article.parse() | |
| text = article.text | |
| except Exception as e: | |
| return f"❌ Failed to extract article: {e}", 0 | |
| else: | |
| text = input_text | |
| if not text: | |
| return "❌ No text provided", 0 | |
| try: | |
| result = model(text)[0] | |
| label = result["label"] | |
| score = result["score"] | |
| verdict = "Authentic" if label == "REAL" else "Possibly Misinformation" | |
| authenticity_score = round(score * 100, 2) | |
| return verdict, authenticity_score | |
| except Exception as e: | |
| return f"❌ Model inference failed: {e}", 0 | |
| interface = gr.Interface( | |
| fn=analyze, | |
| inputs=[ | |
| gr.Textbox(lines=6, label="Paste article text or URL here"), | |
| gr.Radio(["Auto Detect", "Text", "URL"], label="Input Type", value="Auto Detect") | |
| ], | |
| outputs=[ | |
| gr.Textbox(label="Verdict"), | |
| gr.Number(label="Authenticity Score (%)") | |
| ], | |
| title="Misinformation Detection Dashboard", | |
| description="Enter article text or a URL to detect whether the content is authentic or possibly misinformation." | |
| ) | |
| interface.launch() | |