Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Simulaci贸n de las APIs (sustituir por las URLs reales de las APIs)
|
| 6 |
+
LLAMA_API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-11B-Vision-Instruct""
|
| 7 |
+
FLUX_API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
| 8 |
+
COGVIDEO_API_URL = DiffusionPipeline.from_pretrained("bertjiazheng/KoolCogVideoX-5b")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
st.title("ChatBot Multi-IA")
|
| 12 |
+
|
| 13 |
+
# Secci贸n para chat y an谩lisis de im谩genes (meta-llama/Llama-3.2-11B-Vision-Instruct)
|
| 14 |
+
st.header("Chat y an谩lisis de im谩genes")
|
| 15 |
+
|
| 16 |
+
# Entrada de texto para chat
|
| 17 |
+
user_input = st.text_area("Escribe tu pregunta o sube una imagen para analizar", "")
|
| 18 |
+
|
| 19 |
+
# Entrada de imagen para an谩lisis
|
| 20 |
+
uploaded_image = st.file_uploader("Sube una imagen para que la IA la analice", type=["png", "jpg", "jpeg"])
|
| 21 |
+
|
| 22 |
+
# Bot贸n para enviar la consulta
|
| 23 |
+
if st.button("Enviar para an谩lisis"):
|
| 24 |
+
if uploaded_image:
|
| 25 |
+
# Enviar la imagen a la API de an谩lisis de im谩genes
|
| 26 |
+
files = {"image": uploaded_image.getvalue()}
|
| 27 |
+
response = requests.post(LLAMA_API_URL, files=files)
|
| 28 |
+
st.image(uploaded_image, caption="Imagen subida", use_column_width=True)
|
| 29 |
+
st.write("Respuesta de an谩lisis:", response.text)
|
| 30 |
+
elif user_input:
|
| 31 |
+
# Enviar el texto al modelo Llama para chat
|
| 32 |
+
data = {"text": user_input}
|
| 33 |
+
response = requests.post(LLAMA_API_URL, json=data)
|
| 34 |
+
st.write("Respuesta del chat:", response.text)
|
| 35 |
+
else:
|
| 36 |
+
st.warning("Escribe algo o sube una imagen para an谩lisis")
|
| 37 |
+
|
| 38 |
+
# Secci贸n para generaci贸n de im谩genes (black-forest-labs/FLUX.1-dev)
|
| 39 |
+
st.header("Generaci贸n de im谩genes")
|
| 40 |
+
|
| 41 |
+
# Entrada de texto para la generaci贸n de imagen
|
| 42 |
+
image_prompt = st.text_input("Describe la imagen que deseas generar", "")
|
| 43 |
+
|
| 44 |
+
# Bot贸n para generar la imagen
|
| 45 |
+
if st.button("Generar imagen"):
|
| 46 |
+
if image_prompt:
|
| 47 |
+
# Enviar la descripci贸n al modelo FLUX.1-dev
|
| 48 |
+
data = {"prompt": image_prompt}
|
| 49 |
+
response = requests.post(FLUX_API_URL, json=data)
|
| 50 |
+
st.image(response.content, caption="Imagen generada", use_column_width=True)
|
| 51 |
+
else:
|
| 52 |
+
st.warning("Por favor, ingresa una descripci贸n para generar una imagen.")
|
| 53 |
+
|
| 54 |
+
# Secci贸n para generaci贸n de video (THUDM/CogVideoX-5b)
|
| 55 |
+
st.header("Generaci贸n de video")
|
| 56 |
+
|
| 57 |
+
# Entrada de texto para la generaci贸n de video
|
| 58 |
+
video_prompt = st.text_input("Describe el video que deseas generar", "")
|
| 59 |
+
|
| 60 |
+
# Bot贸n para generar el video
|
| 61 |
+
if st.button("Generar video"):
|
| 62 |
+
if video_prompt:
|
| 63 |
+
# Enviar la descripci贸n al modelo CogVideoX-5b
|
| 64 |
+
data = {"prompt": video_prompt}
|
| 65 |
+
response = requests.post(COGVIDEO_API_URL, json=data)
|
| 66 |
+
# Guardar y mostrar el video generado
|
| 67 |
+
with open("video_generado.mp4", "wb") as f:
|
| 68 |
+
f.write(response.content)
|
| 69 |
+
st.video("video_generado.mp4")
|
| 70 |
+
else:
|
| 71 |
+
st.warning("Por favor, ingresa una descripci贸n para generar un video.")
|
| 72 |
+
|
| 73 |
+
# Footer
|
| 74 |
+
st.write("Aplicaci贸n que combina chat, generaci贸n de im谩genes y videos con m煤ltiples IAs.")
|