mdr123 commited on
Commit
8d0dfed
1 Parent(s): f8e1514

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ st.title("Ask Codestral-22B-v0.1")
6
+
7
+ hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
8
+ api_url = "https://api-inference.huggingface.co/models/Codestral-22B-v0.1"
9
+
10
+ headers = {
11
+ "Authorization": f"Bearer {hf_token}"
12
+ }
13
+
14
+ question = st.text_input("Enter your question:")
15
+ submit_button = st.button("Submit")
16
+
17
+ if submit_button and question:
18
+ with st.spinner("Generating answer..."):
19
+ try:
20
+ response = requests.post(
21
+ api_url,
22
+ headers=headers,
23
+ json={"inputs": question}
24
+ )
25
+ response.raise_for_status()
26
+ result = response.json()
27
+ answer = result[0]['generated_text']
28
+ st.text_area("Answer", value=answer, height=200)
29
+ except requests.exceptions.RequestException as e:
30
+ st.error(f"Error calling the API: {e}")
31
+ except KeyError:
32
+ st.error("Error processing the API response.")