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() |