Spaces:
Runtime error
Runtime error
File size: 1,079 Bytes
8d0dfed 6499363 ae6eac8 8d0dfed |
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
import os
st.title("Ask Codestral-22B-v0.1")
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
st.write(hf_token)
api_url = "https://api-inference.huggingface.co/models/mistralai/Codestral-22B-v0.1" # Update with correct owner and model name
headers = {
"Authorization": f"Bearer {hf_token}"
}
question = st.text_input("Enter your question:")
submit_button = st.button("Submit")
if submit_button and question:
with st.spinner("Generating answer..."):
try:
response = requests.post(
api_url,
headers=headers,
json={"inputs": question}
)
response.raise_for_status()
result = response.json()
answer = result[0]['generated_text']
st.text_area("Answer", value=answer, height=200)
except requests.exceptions.RequestException as e:
st.error(f"Error calling the API: {e}")
except KeyError:
st.error("Error processing the API response.")
|