Create pages/3_Codestral.py
Browse files- pages/3_Codestral.py +23 -0
pages/3_Codestral.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from clarifai.client.model import Model
|
4 |
+
|
5 |
+
# Read API key from environment variable
|
6 |
+
api_key = os.getenv("CodestralPat")
|
7 |
+
|
8 |
+
# Function to get prediction from the model
|
9 |
+
def get_model_prediction(prompt):
|
10 |
+
model_url = "https://clarifai.com/mistralai/completion/models/codestral-22b-instruct"
|
11 |
+
model = Model(url=model_url, pat=api_key)
|
12 |
+
model_prediction = model.predict_by_bytes(prompt.encode(), input_type="text")
|
13 |
+
return model_prediction.outputs[0].data.text.raw
|
14 |
+
|
15 |
+
# Streamlit interface
|
16 |
+
st.title("Codestral with Clarifai")
|
17 |
+
|
18 |
+
prompt = st.text_input("Enter your prompt:", "What's the future of AI?")
|
19 |
+
|
20 |
+
if st.button("Get Prediction"):
|
21 |
+
prediction = get_model_prediction(prompt)
|
22 |
+
st.write("Model Prediction:")
|
23 |
+
st.write(prediction)
|