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