Download App.py from Jimmy-123/crypto: direct link, hf CLI and curl.
- Browser
- Download file 3.25 kB
-
https://huggingface.co/spaces/Jimmy-123/crypto/resolve/main/App.py
- Command line
-
hf download hf://spaces/Jimmy-123/crypto/App.py
-
curl -L -o App.py https://huggingface.co/spaces/Jimmy-123/crypto/resolve/main/App.py
3.25 kB
| # -*- 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() |