missbaj commited on
Commit
530df2d
·
verified ·
1 Parent(s): 264feca
Files changed (1) hide show
  1. app.py +37 -46
app.py CHANGED
@@ -1,52 +1,43 @@
 
1
  import requests
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import gradio as gr
4
 
5
- # Load LLaMA-like model from Hugging Face (replace with actual model)
6
- tokenizer = AutoTokenizer.from_pretrained("LaierTwoLabsInc/Satoshi-7B")
7
- model = AutoModelForCausalLM.from_pretrained("LaierTwoLabsInc/Satoshi-7B")
8
 
9
- # Function to fetch current crypto price from CoinGecko
10
- def fetch_crypto_price(crypto_id):
11
- url = f"https://api.coingecko.com/api/v3/simple/price"
12
- params = {'ids': crypto_id, 'vs_currencies': 'usd'}
13
  response = requests.get(url, params=params)
14
  if response.status_code == 200:
15
- return response.json().get(crypto_id, {}).get('usd', 'Unavailable')
16
- return "Error fetching price"
17
-
18
- # Function to fetch crypto news (dummy placeholder function, replace with an actual news API)
19
- def fetch_crypto_news():
20
- # You can replace this with a real API call (e.g., from NewsAPI or CoinTelegraph API)
21
- return "Latest news: Bitcoin continues to rise amid market uncertainties."
22
-
23
- # Function to generate AI analysis from LLaMA model
24
- def generate_crypto_analysis(prompt):
25
- inputs = tokenizer(prompt, return_tensors="pt")
26
- outputs = model.generate(**inputs, max_new_tokens=150)
27
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
28
-
29
- # Main function that integrates real-time data and model analysis
30
- def analyze_crypto():
31
- # Fetch real-time data
32
- btc_price = fetch_crypto_price("bitcoin")
33
- crypto_news = fetch_crypto_news()
34
-
35
- # Create prompt based on fetched data
36
- prompt = f"Bitcoin's current price is ${btc_price}. {crypto_news}. What does this mean for investors?"
37
-
38
- # Generate analysis using the LLaMA model
39
- analysis = generate_crypto_analysis(prompt)
40
-
41
- # Return final analysis
42
- return f"Price: ${btc_price}\nNews: {crypto_news}\nAI Analysis: {analysis}"
43
-
44
- # Gradio Interface
45
- def crypto_dashboard():
46
- return analyze_crypto()
47
-
48
- # Create Gradio interface for real-time crypto analysis
49
- iface = gr.Interface(fn=crypto_dashboard, inputs=[], outputs="text")
50
-
51
- # Launch Gradio app
52
- iface.launch()
 
1
+ import gradio as gr
2
  import requests
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
+ import torch
5
 
6
+ # Load the GPT-Neo 1.3B model and tokenizer
7
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
8
+ model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
9
 
10
+ # Function to fetch Bitcoin price from CoinGecko API
11
+ def fetch_btc_price():
12
+ url = "https://api.coingecko.com/api/v3/simple/price"
13
+ params = {'ids': 'bitcoin', 'vs_currencies': 'usd'}
14
  response = requests.get(url, params=params)
15
  if response.status_code == 200:
16
+ data = response.json()
17
+ return data['bitcoin']['usd']
18
+ return None
19
+
20
+ # Generate crypto insights based on BTC price using GPT-Neo
21
+ def generate_crypto_insight():
22
+ btc_price = fetch_btc_price()
23
+ if btc_price:
24
+ prompt = f"Bitcoin's current price is ${btc_price}. What is the future outlook for the cryptocurrency market? Provide advice for long-term investors."
25
+ inputs = tokenizer(prompt, return_tensors="pt")
26
+ outputs = model.generate(**inputs, max_length=150)
27
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
28
+ else:
29
+ return "Error fetching Bitcoin price."
30
+
31
+ # Define the Gradio interface
32
+ def crypto_analysis():
33
+ return generate_crypto_insight()
34
+
35
+ # Create Gradio interface
36
+ gr_interface = gr.Interface(fn=crypto_analysis,
37
+ inputs=None,
38
+ outputs="text",
39
+ title="Real-Time Crypto Analysis",
40
+ description="Fetch the current Bitcoin price and get market insights using GPT-Neo.")
41
+
42
+ # Launch the app
43
+ gr_interface.launch()