Spaces:
Runtime error
Runtime error
File size: 1,123 Bytes
d83e91b e303211 3dcf766 d83e91b 3dcf766 d83e91b 3dcf766 d83e91b 3dcf766 42b61b5 d83e91b 3dcf766 d83e91b | 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 | import streamlit as st
import requests
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
st.title("Chat con AI")
if "history" not in st.session_state:
st.session_state.history = []
user_input = st.text_input("Scrivi il tuo messaggio:")
if st.button("Invia"):
if user_input:
st.session_state.history.append(("User", user_input))
response = query({"inputs": user_input})
# Verifica se la risposta contiene i dati attesi
if isinstance(response, list) and len(response) > 0 and "generated_text" in response[0]:
bot_response = response[0]["generated_text"]
else:
bot_response = "Errore nella risposta del modello."
st.session_state.history.append(("Bot", bot_response))
if st.session_state.history:
for sender, message in st.session_state.history:
st.write(f"**{sender}:** {message}")
|