File size: 3,829 Bytes
71acbaf
ca7840e
ea57447
 
 
c1f4f65
ea57447
 
c1f4f65
ea57447
 
 
 
 
 
 
 
 
c1f4f65
ea57447
 
 
 
 
 
 
bc93fdd
ea57447
 
 
 
 
 
 
 
b8de2f4
ea57447
 
 
 
 
 
 
 
 
ca7840e
ea57447
 
 
 
 
 
 
 
 
c1f4f65
ea57447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f4f65
ea57447
 
 
 
 
71acbaf
ea57447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8de2f4
ea57447
 
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
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

# 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")
    df['RSI'] = ta.rsi(df['close'], length=14)
    macd = ta.macd(df['close'])
    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'])
    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))

def analyze_sentiment(text):
    analysis = TextBlob(text)
    sentiment = analysis.sentiment.polarity
    if sentiment > 0:
        return "Positivo"
    elif sentiment < 0:
        return "Negativo"
    else:
        return "Neutral"

def predict_prices(df):
    st.subheader("Predicción de Precios")
    X = df.index.values.reshape(-1, 1)
    y = df['close']
    model = LinearRegression()
    model.fit(X, y)
    future = pd.DataFrame({"Index": range(len(df), len(df) + 5)})
    predictions = model.predict(future)
    st.write("Predicciones de precios futuros:", predictions)

def fetch_crypto_data():
    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.header("Chat Interactivo")
    user_input = st.text_input("Escribe tu mensaje aquí:")
    if user_input:
        st.write(f"Tú: {user_input}")
        # Aquí agregarías lógica para procesar la entrada y responder
        st.write("Chatbot: Lo siento, estoy aprendiendo a responder.")

# Main Application
def main():
    st.title("Aplicación de Criptomonedas")
    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":
        query = st.text_input("Ingrese su búsqueda:")
        if query:
            search_web(query)
    elif choice == "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":
        df = fetch_crypto_data()
        if df is not None:
            analyze_crypto_data(df)
    elif choice == "Análisis de Sentimiento":
        text = st.text_area("Ingrese el texto para analizar:")
        if text:
            sentiment = analyze_sentiment(text)
            st.write(f"El sentimiento del texto es: {sentiment}")
    elif choice == "Predicción de Precios":
        df = fetch_crypto_data()
        if df is not None:
            predict_prices(df)

if __name__ == "__main__":
    main()