|
import streamlit as st |
|
import numpy as np |
|
import pandas as pd |
|
from sklearn.ensemble import RandomForestClassifier |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.metrics import accuracy_score |
|
from transformers import pipeline |
|
|
|
|
|
st.title("Aplicación Demo con Hugging Face") |
|
|
|
|
|
st.write(""" |
|
## ¿Qué hace esta aplicación? |
|
Esta aplicación muestra ejemplos básicos usando: |
|
- Clasificación de datos usando Scikit-learn. |
|
- Modelos de texto de Hugging Face con Transformers. |
|
""") |
|
|
|
|
|
st.header("Ejemplo: Clasificación de Datos") |
|
data = pd.DataFrame({ |
|
'Feature 1': np.random.rand(100), |
|
'Feature 2': np.random.rand(100), |
|
'Label': np.random.choice([0, 1], size=100) |
|
}) |
|
|
|
st.write("### Dataset") |
|
st.write(data) |
|
|
|
X = data[['Feature 1', 'Feature 2']] |
|
y = data['Label'] |
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) |
|
model = RandomForestClassifier() |
|
model.fit(X_train, y_train) |
|
predictions = model.predict(X_test) |
|
accuracy = accuracy_score(y_test, predictions) |
|
|
|
st.write("### Precisión del Modelo:") |
|
st.write(f"{accuracy:.2f}") |
|
|
|
|
|
st.header("Ejemplo: Uso de Hugging Face Transformers") |
|
st.write("Genera texto a partir de una entrada") |
|
|
|
|
|
generator = pipeline("text-generation", model="distilgpt2") |
|
input_text = st.text_input("Escribe un texto:") |
|
if st.button("Generar Texto"): |
|
if input_text: |
|
result = generator(input_text, max_length=50, num_return_sequences=1) |
|
st.write(result[0]['generated_text']) |
|
else: |
|
st.write("Por favor, escribe un texto para generar.") |
|
|
|
|
|
st.write("Desarrollado por [TU VIEJA](https://huggingface.co/) 👨💻") |
|
|
|
|