#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ app.py - BERT-CryptoTalk Inference Gradio Space Author: Esteban Description: Secure Gradio app serving S-Dreamer/BERT-CryptoTalk model via Hugging Face Inference API. """ import os import requests import gradio as gr # Retrieve Hugging Face token securely from Hugging Face Secrets HF_TOKEN = os.getenv("HF_TOKEN") if not HF_TOKEN: raise EnvironmentError("HF_TOKEN not set in Hugging Face Space Secrets.") # Inference API endpoint API_URL = "https://api-inference.huggingface.co/models/S-Dreamer/BERT-CryptoTalk" HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"} def classify_crypto_talk(text): """ Sends text to the Hugging Face Inference API and returns model predictions. """ payload = {"inputs": text} response = requests.post(API_URL, headers=HEADERS, json=payload) if response.status_code == 200: return response.json() else: return {"error": response.text, "status_code": response.status_code} # Gradio UI with gr.Blocks(title="🪙 BERT CryptoTalk Inference") as demo: with gr.Row(): gr.Markdown("## 🪙 BERT CryptoTalk Sentiment Inference") with gr.Row(): input_text = gr.Textbox(label="Input Text", lines=4, placeholder="Enter crypto-related news or tweet...") with gr.Row(): predict_button = gr.Button("Predict") output_json = gr.JSON(label="Prediction Result") predict_button.click(fn=classify_crypto_talk, inputs=input_text, outputs=output_json) # Run the app if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)