|
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 |
|
|
|
|
|
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}") |
|
|
|
st.write("Chatbot: Lo siento, estoy aprendiendo a responder.") |
|
|
|
|
|
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() |
|
|