likhonsheikh commited on
Commit
d998544
Β·
verified Β·
1 Parent(s): 414494a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -76
app.py CHANGED
@@ -1,78 +1,15 @@
1
- import requests
2
- import gradio as gr
3
-
4
- # Define token names and CoinGecko IDs
5
- TOKENS = {
6
- "Ethereum": "ethereum",
7
- "Rubic": "rubic",
8
- "Algebra": "algebra"
9
- }
10
-
11
- # Fetch price data with error handling
12
- def fetch_prices():
13
- ids = ",".join(TOKENS.values())
14
- url = "https://api.coingecko.com/api/v3/coins/markets"
15
- params = {
16
- "vs_currency": "usd",
17
- "ids": ids
18
- }
19
-
20
- try:
21
- response = requests.get(url, params=params)
22
- data = response.json()
23
-
24
- if not isinstance(data, list):
25
- raise ValueError("Invalid API response format")
26
-
27
- results = []
28
- for token in data:
29
- name = token.get("name", "Unknown")
30
- symbol = token.get("symbol", "").upper()
31
- price = round(token.get("current_price", 6), 6)
32
- change = round(token.get("price_change_percentage_24h", 0), 2)
33
- color = "🟒" if change > 0 else "πŸ”΄"
34
- results.append(f"{color} **{name} ({symbol})**: ${price} ({change}%)")
35
-
36
- return "\n".join(results)
37
-
38
- except Exception as e:
39
- return f"❌ Error fetching prices: {str(e)}"
40
-
41
- # Gradio UI: Enhance with Chatbot UI and interactive styling
42
- def render_prices():
43
- return fetch_prices()
44
-
45
- with gr.Blocks() as demo:
46
- gr.Markdown("""
47
- ## **πŸ’Ž Rubic Crypto Price Widget v1.2.0**
48
- Welcome to the **Rubic Crypto Price Widget**! πŸš€
49
- Track real-time prices for top cryptocurrencies including **Ethereum (ETH)**, **Rubic (RBC)**, and **Algebra (ALGB)**.
50
-
51
- ### Features:
52
- - 🌐 Live market prices
53
- - πŸ“ˆ 24h price change with color-coded indicators
54
- - βœ… Enhanced user-friendly chat interface
55
-
56
- ### Commands:
57
- - Type `price` to get the latest prices.
58
- - Type `help` for instructions.
59
-
60
- _Stay updated with the crypto world, effortlessly!_
61
- """)
62
-
63
- # Initialize chat interface
64
- chatbot = gr.Chatbot(label="Crypto Chatbot")
65
-
66
- # Send and receive messages from chatbot
67
- def handle_message(message, chat_history):
68
- if message.lower() in ['price', 'prices']:
69
- prices = fetch_prices()
70
- chat_history.append(("Bot", prices))
71
- else:
72
- chat_history.append(("Bot", "πŸ” I can only help with prices. Type `price` to get crypto prices."))
73
- return chat_history, ""
74
-
75
- # Chatbot input
76
  chatbot.submit(handle_message, inputs=[gr.Textbox(), chatbot], outputs=[chatbot, gr.Textbox()])
 
 
 
 
77
 
78
- demo.launch()
 
 
 
 
 
1
+ Reason: /home/user/app/app.py:64: UserWarning: You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.
2
+ chatbot = gr.Chatbot(label="Crypto Chatbot")
3
+ Traceback (most recent call last):
4
+ File "/home/user/app/app.py", line 76, in <module>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  chatbot.submit(handle_message, inputs=[gr.Textbox(), chatbot], outputs=[chatbot, gr.Textbox()])
6
+ AttributeError: 'Chatbot' object has no attribute 'submit'
7
+ Container logs:
8
+
9
+ ===== Application Startup at 2025-04-29 23:07:23 =====
10
 
11
+ /home/user/app/app.py:64: UserWarning: You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.
12
+ chatbot = gr.Chatbot(label="Crypto Chatbot")
13
+ Traceback (most recent call last):
14
+ File "/home/user/app/app.py", line 76, in <module>
15
+ chatbot.submit(handle_message, inputs=[gr.Textbox(), chatbot], outputs=[chatbot, gr.Textbox()])