coderemote / app.py
mdr123's picture
Upload app.py
d869263 verified
raw
history blame
1.02 kB
import streamlit as st
import requests
import os
st.title("Ask Codestral-22B-v0.1")
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
api_url = "https://api-inference.huggingface.co/models/mistralai/Codestral-22B-v0.1"
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.")