- Dockerfile +29 -0
- README.md +5 -6
- app.py +65 -0
- prueba.py +1 -0
- requirements.py +7 -0
- train_model.py +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
# Crear un usuario no root
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
|
| 6 |
+
# Cambiar al usuario root para poder modificar el archivo /etc/environment
|
| 7 |
+
USER root
|
| 8 |
+
|
| 9 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 10 |
+
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Copiar los archivos necesarios
|
| 14 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 15 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 16 |
+
|
| 17 |
+
# Copiar los archivos de la aplicación
|
| 18 |
+
COPY --chown=user . /app
|
| 19 |
+
|
| 20 |
+
# Establecer una variable de entorno PORT con un valor aleatorio
|
| 21 |
+
RUN echo "PORT=$(shuf -i 10000-65000 -n 1)" >> /etc/environment
|
| 22 |
+
|
| 23 |
+
# Exponer el puerto (aunque este valor será reemplazado por el puerto aleatorio)
|
| 24 |
+
EXPOSE 7860
|
| 25 |
+
|
| 26 |
+
#RUN python app.py --fine-tune
|
| 27 |
+
|
| 28 |
+
# Usar la variable de entorno PORT para ejecutar la app
|
| 29 |
+
CMD ["bash", "-c", "source /etc/environment && uvicorn app:app --host 0.0.0.0 --port $PORT"]
|
README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
sdk_version: 1.43.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Amigo
|
| 3 |
+
emoji: 👁
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
---
|
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import uvicorn
|
| 6 |
+
import threading
|
| 7 |
+
from transformers import AutoTokenizer
|
| 8 |
+
import torch
|
| 9 |
+
|
| 10 |
+
# ======== Cargar el modelo DialoGPT =========
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# ======== Definir API con FastAPI =========
|
| 15 |
+
app = FastAPI()
|
| 16 |
+
|
| 17 |
+
class Message(BaseModel):
|
| 18 |
+
text: str
|
| 19 |
+
|
| 20 |
+
@app.post("/chat")
|
| 21 |
+
def chat(msg: Message):
|
| 22 |
+
"""Genera respuesta basada en el input del usuario."""
|
| 23 |
+
input_text = msg.text # Texto de entrada
|
| 24 |
+
print(f"Mensaje recibido: {input_text}")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Codificar el texto de entrada y agregar el token de fin de secuencia
|
| 28 |
+
inputs = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt")
|
| 29 |
+
|
| 30 |
+
# Generar la respuesta
|
| 31 |
+
response_ids = model.generate(inputs,
|
| 32 |
+
max_length=100, # Longitud máxima de la respuesta
|
| 33 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 34 |
+
no_repeat_ngram_size=2, # Evitar repeticiones
|
| 35 |
+
top_p=0.95, # Top-p sampling para mayor diversidad
|
| 36 |
+
top_k=60) # Top-k sampling
|
| 37 |
+
|
| 38 |
+
# Decodificar la respuesta generada
|
| 39 |
+
response_text = tokenizer.decode(response_ids[:, inputs.shape[-1]:][0], skip_special_tokens=True)
|
| 40 |
+
|
| 41 |
+
print(f"Respuesta generada: {response_text}")
|
| 42 |
+
|
| 43 |
+
return {"response": response_text}
|
| 44 |
+
#young preteen, very slender, fair skin, very large breasts, straight red hair, legs spread putting a finger in the anus and another in the pussy, naked photorealistic, high detail
|
| 45 |
+
#young preteen, very slender, fair skin, very large breasts, doggy sexy pose, show pussy naked
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#joven adolescente en posición de perrita sexy, enseñando las nalgas y la vagina
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# ======== Función para ejecutar FastAPI en segundo plano =========
|
| 52 |
+
def run_api():
|
| 53 |
+
port = int(os.getenv("PORT", 7860))
|
| 54 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 55 |
+
|
| 56 |
+
threading.Thread(target=run_api, daemon=True).start()
|
| 57 |
+
|
| 58 |
+
# ======== Interfaz con Streamlit =========
|
| 59 |
+
st.title("Mi Amigo Virtual 🤖")
|
| 60 |
+
st.write("Escríbeme algo y te responderé!")
|
| 61 |
+
|
| 62 |
+
user_input = st.text_input("Tú:")
|
| 63 |
+
if user_input:
|
| 64 |
+
response = chat(Message(text=user_input))
|
| 65 |
+
st.write("🤖:", response["response"])
|
prueba.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
print("Hola")
|
requirements.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
+
streamlit
|
| 6 |
+
pydantic
|
| 7 |
+
datasets
|
train_model.py
ADDED
|
File without changes
|