mayaAI-beta / app.py
qspacecorp's picture
Update app.py
42b61b5 verified
Raw History Blame Contribute Delete
1.12 kB
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}")