Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Establecer una carpeta accesible para cach茅
|
| 7 |
+
os.environ['HF_HOME'] = '/tmp/hf_cache'
|
| 8 |
+
|
| 9 |
+
# Descargar el modelo GGUF
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def cargar_modelo():
|
| 12 |
+
model_path = hf_hub_download(
|
| 13 |
+
repo_id="unsloth/Llama-4-Scout-17B-16E-Instruct-GGUF",
|
| 14 |
+
filename="Llama-4-Scout-17B-16E-Instruct-UD-IQ1_S.gguf"
|
| 15 |
+
)
|
| 16 |
+
llm = Llama(
|
| 17 |
+
model_path=model_path,
|
| 18 |
+
n_ctx=2048,
|
| 19 |
+
n_threads=4
|
| 20 |
+
)
|
| 21 |
+
return llm
|
| 22 |
+
|
| 23 |
+
llm = cargar_modelo()
|
| 24 |
+
|
| 25 |
+
# T铆tulo del Streamlit App
|
| 26 |
+
st.title("馃 Llama-4 Scout con llama.cpp (CPU)")
|
| 27 |
+
|
| 28 |
+
# Input del usuario
|
| 29 |
+
prompt = st.text_area("Introduce tu prompt aqu铆:")
|
| 30 |
+
|
| 31 |
+
# Bot贸n para generar respuesta
|
| 32 |
+
if st.button("Generar Respuesta"):
|
| 33 |
+
with st.spinner("Generando respuesta..."):
|
| 34 |
+
output = llm.create_chat_completion(
|
| 35 |
+
messages=[{"role": "user", "content": prompt}],
|
| 36 |
+
max_tokens=200
|
| 37 |
+
)
|
| 38 |
+
respuesta = output["choices"][0]["message"]["content"]
|
| 39 |
+
st.markdown(f"### Respuesta:\n{respuesta}")
|