Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import pytesseract
|
|
|
|
| 4 |
import pandas_ta as ta
|
| 5 |
from textblob import TextBlob
|
| 6 |
import pandas as pd
|
|
@@ -9,92 +10,7 @@ from sklearn.linear_model import LinearRegression
|
|
| 9 |
from sklearn.preprocessing import PolynomialFeatures
|
| 10 |
|
| 11 |
# Helper Functions
|
| 12 |
-
|
| 13 |
-
from googlesearch import search
|
| 14 |
-
st.subheader("Resultados de la Búsqueda Web")
|
| 15 |
-
results = []
|
| 16 |
-
for result in search(query, num_results=5):
|
| 17 |
-
results.append(result)
|
| 18 |
-
for idx, link in enumerate(results):
|
| 19 |
-
st.write(f"{idx + 1}. {link}")
|
| 20 |
-
|
| 21 |
-
def analyze_image(uploaded_file):
|
| 22 |
-
st.subheader("Análisis de Imagen")
|
| 23 |
-
image = Image.open(uploaded_file)
|
| 24 |
-
st.image(image, caption="Imagen cargada", use_column_width=True)
|
| 25 |
-
text = pytesseract.image_to_string(image)
|
| 26 |
-
st.write("Texto extraído de la imagen:")
|
| 27 |
-
st.write(text)
|
| 28 |
-
|
| 29 |
-
def analyze_crypto_data(df):
|
| 30 |
-
st.subheader("Análisis Técnico")
|
| 31 |
-
try:
|
| 32 |
-
df['RSI'] = ta.rsi(df['close'], length=14)
|
| 33 |
-
macd = ta.macd(df['close'])
|
| 34 |
-
if macd is not None:
|
| 35 |
-
df['MACD'], df['MACD_signal'], df['MACD_hist'] = (
|
| 36 |
-
macd['MACD_12_26_9'], macd['MACDs_12_26_9'], macd['MACDh_12_26_9']
|
| 37 |
-
)
|
| 38 |
-
bbands = ta.bbands(df['close'])
|
| 39 |
-
if bbands is not None:
|
| 40 |
-
df['BB_Lower'], df['BB_Mid'], df['BB_Upper'] = (
|
| 41 |
-
bbands['BBL_20_2.0'], bbands['BBM_20_2.0'], bbands['BBU_20_2.0']
|
| 42 |
-
)
|
| 43 |
-
st.write(df.tail(10))
|
| 44 |
-
except Exception as e:
|
| 45 |
-
st.error(f"Error en el análisis técnico: {e}")
|
| 46 |
-
|
| 47 |
-
def analyze_sentiment(text):
|
| 48 |
-
st.subheader("Análisis de Sentimiento")
|
| 49 |
-
analysis = TextBlob(text)
|
| 50 |
-
sentiment = analysis.sentiment.polarity
|
| 51 |
-
if sentiment > 0:
|
| 52 |
-
st.write("El sentimiento del texto es: **Positivo**")
|
| 53 |
-
elif sentiment < 0:
|
| 54 |
-
st.write("El sentimiento del texto es: **Negativo**")
|
| 55 |
-
else:
|
| 56 |
-
st.write("El sentimiento del texto es: **Neutral**")
|
| 57 |
-
|
| 58 |
-
def predict_prices(df):
|
| 59 |
-
st.subheader("Predicción de Precios")
|
| 60 |
-
try:
|
| 61 |
-
X = df.index.values.reshape(-1, 1)
|
| 62 |
-
y = df['close']
|
| 63 |
-
poly = PolynomialFeatures(degree=2)
|
| 64 |
-
X_poly = poly.fit_transform(X)
|
| 65 |
-
model = LinearRegression()
|
| 66 |
-
model.fit(X_poly, y)
|
| 67 |
-
future = pd.DataFrame(range(len(df), len(df) + 5), columns=['Index'])
|
| 68 |
-
future_poly = poly.transform(future)
|
| 69 |
-
predictions = model.predict(future_poly)
|
| 70 |
-
st.write("Predicciones de precios futuros:", predictions)
|
| 71 |
-
except Exception as e:
|
| 72 |
-
st.error(f"Error en la predicción de precios: {e}")
|
| 73 |
-
|
| 74 |
-
def fetch_crypto_data():
|
| 75 |
-
st.subheader("Obtención de Datos de Criptomonedas")
|
| 76 |
-
url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=30&interval=daily"
|
| 77 |
-
response = requests.get(url)
|
| 78 |
-
if response.status_code == 200:
|
| 79 |
-
data = response.json()
|
| 80 |
-
prices = [item[1] for item in data['prices']]
|
| 81 |
-
df = pd.DataFrame(prices, columns=['close'])
|
| 82 |
-
return df
|
| 83 |
-
else:
|
| 84 |
-
st.error("Error al obtener datos de criptomonedas.")
|
| 85 |
-
return None
|
| 86 |
-
|
| 87 |
-
def chat_interface():
|
| 88 |
-
st.title("Chat Cripto Analizador")
|
| 89 |
-
st.write("¡Pregúntame algo!")
|
| 90 |
-
user_input = st.text_input("Tu mensaje:", placeholder="Escribe aquí...")
|
| 91 |
-
if user_input:
|
| 92 |
-
if "crypto" in user_input.lower():
|
| 93 |
-
st.write(f"Tú: {user_input}")
|
| 94 |
-
st.write("Bot: Estoy listo para analizar criptomonedas. Intenta seleccionar 'Análisis Técnico' desde la barra lateral.")
|
| 95 |
-
else:
|
| 96 |
-
st.write(f"Tú: {user_input}")
|
| 97 |
-
st.write("Bot: Aún estoy aprendiendo. Por ahora puedo analizar imágenes y criptomonedas.")
|
| 98 |
|
| 99 |
# Main Application
|
| 100 |
def main():
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import pytesseract
|
| 4 |
+
from numpy import nan as NaN # Parche para pandas-ta
|
| 5 |
import pandas_ta as ta
|
| 6 |
from textblob import TextBlob
|
| 7 |
import pandas as pd
|
|
|
|
| 10 |
from sklearn.preprocessing import PolynomialFeatures
|
| 11 |
|
| 12 |
# Helper Functions
|
| 13 |
+
# (Mismo código proporcionado anteriormente en las funciones)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Main Application
|
| 16 |
def main():
|