File size: 5,045 Bytes
71acbaf
ca7840e
ea57447
 
 
c1f4f65
ea57447
 
f3fb038
c1f4f65
ea57447
 
 
 
 
 
 
 
 
c1f4f65
ea57447
 
 
 
 
 
 
bc93fdd
ea57447
 
f3fb038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8de2f4
ea57447
f3fb038
ea57447
 
 
f3fb038
ea57447
f3fb038
ea57447
f3fb038
ca7840e
ea57447
 
f3fb038
 
 
 
 
 
 
 
 
 
 
 
 
c1f4f65
ea57447
f3fb038
ea57447
 
 
 
 
 
 
 
 
 
 
 
f3fb038
 
 
ea57447
f3fb038
 
 
 
 
 
c1f4f65
ea57447
 
f3fb038
 
 
 
 
ea57447
71acbaf
ea57447
 
 
f3fb038
ea57447
 
 
 
f3fb038
ea57447
 
 
 
f3fb038
ea57447
 
 
 
f3fb038
ea57447
 
f3fb038
ea57447
f3fb038
ea57447
 
 
b8de2f4
ea57447
 
6d0b640
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import streamlit as st
from PIL import Image
import pytesseract
import pandas_ta as ta
from textblob import TextBlob
import pandas as pd
import requests
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures

# Helper Functions
def search_web(query):
    from googlesearch import search
    st.subheader("Resultados de la Búsqueda Web")
    results = []
    for result in search(query, num_results=5):
        results.append(result)
    for idx, link in enumerate(results):
        st.write(f"{idx + 1}. {link}")

def analyze_image(uploaded_file):
    st.subheader("Análisis de Imagen")
    image = Image.open(uploaded_file)
    st.image(image, caption="Imagen cargada", use_column_width=True)
    text = pytesseract.image_to_string(image)
    st.write("Texto extraído de la imagen:")
    st.write(text)

def analyze_crypto_data(df):
    st.subheader("Análisis Técnico")
    try:
        df['RSI'] = ta.rsi(df['close'], length=14)
        macd = ta.macd(df['close'])
        if macd is not None:
            df['MACD'], df['MACD_signal'], df['MACD_hist'] = (
                macd['MACD_12_26_9'], macd['MACDs_12_26_9'], macd['MACDh_12_26_9']
            )
        bbands = ta.bbands(df['close'])
        if bbands is not None:
            df['BB_Lower'], df['BB_Mid'], df['BB_Upper'] = (
                bbands['BBL_20_2.0'], bbands['BBM_20_2.0'], bbands['BBU_20_2.0']
            )
        st.write(df.tail(10))
    except Exception as e:
        st.error(f"Error en el análisis técnico: {e}")

def analyze_sentiment(text):
    st.subheader("Análisis de Sentimiento")
    analysis = TextBlob(text)
    sentiment = analysis.sentiment.polarity
    if sentiment > 0:
        st.write("El sentimiento del texto es: **Positivo**")
    elif sentiment < 0:
        st.write("El sentimiento del texto es: **Negativo**")
    else:
        st.write("El sentimiento del texto es: **Neutral**")

def predict_prices(df):
    st.subheader("Predicción de Precios")
    try:
        X = df.index.values.reshape(-1, 1)
        y = df['close']
        poly = PolynomialFeatures(degree=2)
        X_poly = poly.fit_transform(X)
        model = LinearRegression()
        model.fit(X_poly, y)
        future = pd.DataFrame(range(len(df), len(df) + 5), columns=['Index'])
        future_poly = poly.transform(future)
        predictions = model.predict(future_poly)
        st.write("Predicciones de precios futuros:", predictions)
    except Exception as e:
        st.error(f"Error en la predicción de precios: {e}")

def fetch_crypto_data():
    st.subheader("Obtención de Datos de Criptomonedas")
    url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=30&interval=daily"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        prices = [item[1] for item in data['prices']]
        df = pd.DataFrame(prices, columns=['close'])
        return df
    else:
        st.error("Error al obtener datos de criptomonedas.")
        return None

def chat_interface():
    st.title("Chat Cripto Analizador")
    st.write("¡Pregúntame algo!")
    user_input = st.text_input("Tu mensaje:", placeholder="Escribe aquí...")
    if user_input:
        if "crypto" in user_input.lower():
            st.write(f"Tú: {user_input}")
            st.write("Bot: Estoy listo para analizar criptomonedas. Intenta seleccionar 'Análisis Técnico' desde la barra lateral.")
        else:
            st.write(f"Tú: {user_input}")
            st.write("Bot: Aún estoy aprendiendo. Por ahora puedo analizar imágenes y criptomonedas.")

# Main Application
def main():
    st.sidebar.title("Menú")
    menu = [
        "Chat", "Búsqueda Web", "Análisis de Imágenes", 
        "Análisis Técnico", "Análisis de Sentimiento", "Predicción de Precios"
    ]
    choice = st.sidebar.selectbox("Seleccione una opción", menu)

    if choice == "Chat":
        chat_interface()
    elif choice == "Búsqueda Web":
        st.header("Búsqueda Web")
        query = st.text_input("Ingrese su búsqueda:")
        if query:
            search_web(query)
    elif choice == "Análisis de Imágenes":
        st.header("Análisis de Imágenes")
        uploaded_file = st.file_uploader("Suba una imagen", type=["png", "jpg", "jpeg"])
        if uploaded_file:
            analyze_image(uploaded_file)
    elif choice == "Análisis Técnico":
        st.header("Análisis Técnico de Criptomonedas")
        df = fetch_crypto_data()
        if df is not None:
            analyze_crypto_data(df)
    elif choice == "Análisis de Sentimiento":
        st.header("Análisis de Sentimiento")
        text = st.text_area("Ingrese el texto para analizar:")
        if text:
            analyze_sentiment(text)
    elif choice == "Predicción de Precios":
        st.header("Predicción de Precios de Criptomonedas")
        df = fetch_crypto_data()
        if df is not None:
            predict_prices(df)

if __name__ == "__main__":
    main()