File size: 3,251 Bytes
d74319e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""app.py

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1BW8jLOtkg1Z3MkPb4f4fDyrQ7b6jBnvJ
"""

import gradio as gr

# Bot Identity
bot_name = "CryptoBuddy"
bot_tone = "Friendly and eco-conscious"

# Sample Crypto Dataset
crypto_db = {
    "Bitcoin": {
        "price_trend": "rising",
        "market_cap": "high",
        "energy_use": "high",
        "sustainability_score": 3/10
    },
    "Ethereum": {
        "price_trend": "stable",
        "market_cap": "high",
        "energy_use": "medium",
        "sustainability_score": 6/10
    },
    "Cardano": {
        "price_trend": "rising",
        "market_cap": "medium",
        "energy_use": "low",
        "sustainability_score": 8/10
    }
}

def respond_to_query(user_query):
    user_query = user_query.lower()
    if "trending" in user_query or "rising" in user_query:
        trending = [coin for coin, data in crypto_db.items() if data["price_trend"] == "rising"]
        return f"πŸ“ˆ These coins are trending up: {', '.join(trending)}"
    elif "sustainable" in user_query or "eco" in user_query:
        recommend = max(crypto_db, key=lambda x: crypto_db[x]["sustainability_score"])
        return f"🌱 Invest in {recommend}! It’s eco-friendly and has long-term potential."
    elif "high market cap" in user_query:
        high_cap = [coin for coin, data in crypto_db.items() if data["market_cap"] == "high"]
        return f"πŸ’° Coins with high market cap: {', '.join(high_cap)}"
    else:
        return "πŸ€” I’m not sure how to help with that. Try asking about trends or sustainability."

def evaluate_profitability(coin_data):
    if coin_data["price_trend"] == "rising" and coin_data["market_cap"] == "high":
        return "πŸš€ High potential for short-term gains!"
    elif coin_data["price_trend"] == "stable":
        return "πŸ“Š Moderate potential β€” consider holding."
    else:
        return "⚠️ Risky investment at the moment."

def evaluate_sustainability(coin_data):
    if coin_data["energy_use"] == "low" and coin_data["sustainability_score"] > 0.7:
        return "🌱 Strong long-term sustainability!"
    elif coin_data["sustainability_score"] > 0.5:
        return "🌿 Moderate sustainability β€” monitor closely."
    else:
        return "πŸ”₯ Low sustainability β€” high risk."

def get_investment_advice(coin_name):
    coin_name = coin_name.title()
    if coin_name not in crypto_db:
        return "❌ Sorry, I don't have data on that coin."
    data = crypto_db[coin_name]
    profit = evaluate_profitability(data)
    sustain = evaluate_sustainability(data)
    return f"""
πŸ“ˆ Investment Advice for {coin_name}:
- Profitability: {profit}
- Sustainability: {sustain}
"""

def crypto_chatbot(user_input):
    if "advice" in user_input.lower():
        coin = user_input.split()[-1]
        return get_investment_advice(coin)
    else:
        return respond_to_query(user_input)

gr.Interface(
    fn=crypto_chatbot,
    inputs=gr.Textbox(lines=2, placeholder="Ask CryptoBuddy something..."),
    outputs="text",
    title="πŸͺ™ CryptoBuddy Chatbot",
    description="Ask about trending coins, sustainability, or get investment advice!"
).launch()