Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| import os | |
| HF_API_KEY = os.environ.get("HF_API_KEY") | |
| MODEL = "mrm8488/bert-tiny-finetuned-fake-news-detection" | |
| API_URL = f"https://api-inference.huggingface.co/models/{MODEL}" | |
| HEADERS = {"Authorization": f"Bearer {HF_API_KEY}"} | |
| def fact_check(claim: str): | |
| claim = claim.strip() | |
| if not claim: | |
| return "Please type a statement first." | |
| r = requests.post(API_URL, headers=HEADERS, json={"inputs": claim}) | |
| try: | |
| data = r.json() | |
| except Exception: | |
| return f"API error: {r.text}" | |
| if isinstance(data, list) and data and data[0]: | |
| item = data[0][0] | |
| label = item.get("label", "N/A") | |
| score = round(item.get("score", 0) * 100, 2) | |
| return f"Result: {label}\nConfidence: {score}%" | |
| return f"Unexpected response: {data}" | |
| iface = gr.Interface( | |
| fn=fact_check, | |
| inputs=gr.components.Textbox(lines=4, placeholder="Type a statement..."), | |
| outputs="text", | |
| title="AI Fact Checker", | |
| description="Type a statement and press Submit." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |