File size: 3,481 Bytes
7eaa35c
 
 
 
9f238b5
7eaa35c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3a7974
7eaa35c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f2160d
7eaa35c
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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("""
            <div class="footer">
                <a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
                <a href="https://github.com/arad1367" target="_blank">GitHub</a> |
                <a href="https://arad1367.pythonanywhere.com/" target="_blank">Live demo of my PhD defense</a>
                <p>Made with πŸ’– by Pejman Ebrahimi</p>
            </div>
        """)

demo.launch(share=True)