app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,43 @@
|
|
|
|
|
| 1 |
import requests
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 8 |
|
| 9 |
-
# Function to fetch
|
| 10 |
-
def
|
| 11 |
-
url =
|
| 12 |
-
params = {'ids':
|
| 13 |
response = requests.get(url, params=params)
|
| 14 |
if response.status_code == 200:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|