File size: 1,085 Bytes
2bd4753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
import os

# Establecer una carpeta accesible para caché
os.environ['HF_HOME'] = '/tmp/hf_cache'

# Descargar el modelo GGUF
@st.cache_resource
def cargar_modelo():
    model_path = hf_hub_download(
        repo_id="unsloth/Llama-4-Scout-17B-16E-Instruct-GGUF",
        filename="Llama-4-Scout-17B-16E-Instruct-UD-IQ1_S.gguf"
    )
    llm = Llama(
        model_path=model_path,
        n_ctx=2048,
        n_threads=4
    )
    return llm

llm = cargar_modelo()

# Título del Streamlit App
st.title("🦙 Llama-4 Scout con llama.cpp (CPU)")

# Input del usuario
prompt = st.text_area("Introduce tu prompt aquí:")

# Botón para generar respuesta
if st.button("Generar Respuesta"):
    with st.spinner("Generando respuesta..."):
        output = llm.create_chat_completion(
            messages=[{"role": "user", "content": prompt}],
            max_tokens=200
        )
        respuesta = output["choices"][0]["message"]["content"]
        st.markdown(f"### Respuesta:\n{respuesta}")