Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
model_name = "meta-llama/Meta-Llama-Guard-2-8B" # Reemplaza con el nombre del modelo que vas a usar
|
9 |
-
use_auth_token = 'YOUR_HUGGING_FACE_TOKEN'
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=use_auth_token)
|
11 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=use_auth_token)
|
12 |
-
return tokenizer, model
|
13 |
|
14 |
-
|
|
|
|
|
15 |
|
16 |
st.title("LLaMA Chatbot")
|
17 |
st.subheader("Ask anything to the LLaMA model!")
|
18 |
|
19 |
user_input = st.text_input("You: ")
|
20 |
if user_input:
|
21 |
-
|
22 |
-
|
23 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
st.write(f"Chatbot: {response}")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
+
import requests
|
5 |
+
import os
|
6 |
|
7 |
+
# Obtener el token de los secretos
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-Guard-2-8B"
|
9 |
+
headers = {"Authorization": f"Bearer {os.getenv('YOUR_HUGGING_FACE_TOKEN')}"}
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def query(payload):
|
12 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
+
return response.json()
|
14 |
|
15 |
st.title("LLaMA Chatbot")
|
16 |
st.subheader("Ask anything to the LLaMA model!")
|
17 |
|
18 |
user_input = st.text_input("You: ")
|
19 |
if user_input:
|
20 |
+
output = query({"inputs": user_input})
|
21 |
+
response = output.get("generated_text", "Sorry, I couldn't generate a response.")
|
|
|
22 |
st.write(f"Chatbot: {response}")
|