import gradio as gr import torch from transformers import AutoTokenizer, AutoModelForSequenceClassification model_path = "arad1367/crypto_sustainability_news_FacebookAI_roberta-large-mnli" tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForSequenceClassification.from_pretrained(model_path) def crypto_classifier(text: str): inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512) outputs = model(**inputs) probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1) labels = ["Negative", "Neutral", "Positive"] output_dict = {label: prob.item() for label, prob in zip(labels, probabilities[0])} return output_dict custom_css = """ .container { max-width: 1200px; margin: auto; padding: 20px; font-family: 'Inter', system-ui, -apple-system, sans-serif; } .header { text-align: center; margin: 2em 0; color: #2d7ff9; } .description { text-align: center; margin-bottom: 2em; color: #666; } .footer { text-align: center; margin-top: 20px; padding: 20px; border-top: 1px solid #eee; background: #f8f9fa; } .footer a { color: #2d7ff9; text-decoration: none; margin: 0 10px; font-weight: 500; } .footer a:hover { text-decoration: underline; } .duplicate-button { background-color: #2d7ff9 !important; color: white !important; border-radius: 8px !important; padding: 10px 20px !important; margin: 20px auto !important; display: block !important; } """ examples = [ ["The Crypto Conference, focusing on sustainable crypto, will be organized next year."], ["There are growing concerns about the environmental impact of cryptocurrency mining processes."], ["The new blockchain protocol reduces energy consumption by 90%."], ["The decentralized network operates on renewable energy sources."], ["Bitcoin mining contributes to increased carbon emissions in developing countries."] ] with gr.Blocks(theme='earneleh/paris', css=custom_css) as demo: with gr.Column(elem_classes="container"): gr.Markdown("# Cryptocurrency News Sustainability Classifier", elem_classes="header") gr.Markdown( "Analyze cryptocurrency-related text to determine its sustainability implications.", elem_classes="description" ) input_text = gr.Textbox( label="Input Text", placeholder="Enter cryptocurrency-related news or statement...", lines=3 ) output_label = gr.Label(label="Classification Results", num_top_classes=3) submit_btn = gr.Button("Analyze", variant="primary") gr.Examples(examples=examples, inputs=input_text) submit_btn.click(fn=crypto_classifier, inputs=input_text, outputs=output_label) gr.DuplicateButton( value="Duplicate Space for private use", elem_classes="duplicate-button" ) gr.HTML("""
""") demo.launch(share=True)