typesdigital commited on
Commit
261a544
·
1 Parent(s): dc1aaa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -26
app.py CHANGED
@@ -14,18 +14,21 @@ openai.api_key = '<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>'
14
 
15
  # Fetch the latest cryptocurrency prices from the CoinMarketCap API
16
  response = requests.get(url, headers={'X-CMC_PRO_API_KEY': '<03365e9f-2220-4083-90a7-151a70bb40ae>'}, params=parameters)
17
- data = response.json()['data']
18
-
19
- # Extract the relevant data from the API response
20
- bitcoin_price = data[0]['quote']['USD']['price']
21
- ethereum_price = data[1]['quote']['USD']['price']
22
- bitcoin_margin = data[0]['quote']['USD']['percent_change_24h']
23
- ethereum_margin = data[1]['quote']['USD']['percent_change_24h']
24
-
25
- # Use the OpenAI API to generate a prediction for the margin
26
- prompt = f"Based on the latest cryptocurrency prices, what will be the margin for Bitcoin and Ethereum in the next 24 hours?"
27
- model = "text-davinci-002"
28
- response = openai.Completion.create(
 
 
 
29
  engine=model,
30
  prompt=prompt,
31
  temperature=0.5,
@@ -33,17 +36,20 @@ response = openai.Completion.create(
33
  n=1,
34
  stop=None,
35
  timeout=20,
36
- )
37
-
38
- # Extract the predicted margin from the OpenAI API response
39
- predicted_margin = response.choices[0].text.strip()
40
-
41
- # Print the results
42
- print("Latest cryptocurrency prices:")
43
- print(f"Bitcoin: ${bitcoin_price:.2f}")
44
- print(f"Ethereum: ${ethereum_price:.2f}")
45
- print("24-hour margin:")
46
- print(f"Bitcoin: {bitcoin_margin:.2f}%")
47
- print(f"Ethereum: {ethereum_margin:.2f}%")
48
- print("Predicted margin for the next 24 hours:")
49
- print(predicted_margin)
 
 
 
 
14
 
15
  # Fetch the latest cryptocurrency prices from the CoinMarketCap API
16
  response = requests.get(url, headers={'X-CMC_PRO_API_KEY': '<03365e9f-2220-4083-90a7-151a70bb40ae>'}, params=parameters)
17
+
18
+ # Check if the response is successful
19
+ if response.status_code == 200:
20
+ # Extract the data from the API response
21
+ data = response.json()
22
+ # Extract the relevant data from the API response
23
+ bitcoin_price = data['data']['cryptocurrency_list'][0]['quote']['USD']['price']
24
+ ethereum_price = data['data']['cryptocurrency_list'][1]['quote']['USD']['price']
25
+ bitcoin_margin = data['data']['cryptocurrency_list'][0]['quote']['USD']['percent_change_24h']
26
+ ethereum_margin = data['data']['cryptocurrency_list'][1]['quote']['USD']['percent_change_24h']
27
+
28
+ # Use the OpenAI API to generate a prediction for the margin
29
+ prompt = f"Based on the latest cryptocurrency prices, what will be the margin for Bitcoin and Ethereum in the next 24 hours?"
30
+ model = "text-davinci-002"
31
+ response = openai.Completion.create(
32
  engine=model,
33
  prompt=prompt,
34
  temperature=0.5,
 
36
  n=1,
37
  stop=None,
38
  timeout=20,
39
+ )
40
+
41
+ # Extract the predicted margin from the OpenAI API response
42
+ predicted_margin = response.choices[0].text.strip()
43
+
44
+ # Print the results
45
+ print("Latest cryptocurrency prices:")
46
+ print(f"Bitcoin: ${bitcoin_price:.2f}")
47
+ print(f"Ethereum: ${ethereum_price:.2f}")
48
+ print("24-hour margin:")
49
+ print(f"Bitcoin: {bitcoin_margin:.2f}%")
50
+ print(f"Ethereum: {ethereum_margin:.2f}%")
51
+ print("Predicted margin for the next 24 hours:")
52
+ print(predicted_margin)
53
+
54
+ else:
55
+ print("Error: API request failed")