|
import streamlit as st |
|
from PIL import Image |
|
import pytesseract |
|
import pandas as pd |
|
import requests |
|
from textblob import TextBlob |
|
from sklearn.linear_model import LinearRegression |
|
from sklearn.preprocessing import PolynomialFeatures |
|
import talib |
|
|
|
|
|
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) |
|
sentiment = analyze_sentiment(text) |
|
st.write(f"Análisis de sentimiento del texto extraído: {sentiment}") |
|
|
|
|
|
def analyze_crypto_data(df): |
|
st.subheader("Análisis Técnico") |
|
try: |
|
|
|
df['RSI'] = talib.RSI(df['close'], timeperiod=14) |
|
|
|
|
|
macd, macd_signal, macd_hist = talib.MACD( |
|
df['close'], fastperiod=12, slowperiod=26, signalperiod=9 |
|
) |
|
df['MACD'] = macd |
|
df['MACD_signal'] = macd_signal |
|
df['MACD_hist'] = macd_hist |
|
|
|
|
|
upper, middle, lower = talib.BBANDS( |
|
df['close'], timeperiod=20, nbdevup=2, nbdevdn=2, matype=0 |
|
) |
|
df['BB_Upper'] = upper |
|
df['BB_Mid'] = middle |
|
df['BB_Lower'] = lower |
|
|
|
st.write("Últimos 10 datos de análisis técnico:") |
|
st.write(df.tail(10)) |
|
except Exception as e: |
|
st.error(f"Error en el análisis técnico: {e}") |
|
|
|
|
|
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") |
|
try: |
|
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['Index'].values.reshape(-1, 1)) |
|
st.write("Predicciones de precios futuros:") |
|
for i, pred in enumerate(predictions): |
|
st.write(f"Día {len(df) + i + 1}: {pred:.2f} USD") |
|
except Exception as e: |
|
st.error(f"Error al realizar la predicción: {e}") |
|
|
|
|
|
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}") |
|
response = f"No estoy entrenado como ChatGPT, pero aquí estoy para ayudarte. Tú dijiste: {user_input}" |
|
st.write(f"Chatbot: {response}") |
|
|
|
|
|
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() |
|
|
|
|