Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
| 3 |
import torch
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@st.cache_resource
|
| 6 |
def load_model_and_tokenizer(model_id):
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
| 9 |
return model, tokenizer
|
| 10 |
|
|
|
|
| 11 |
def query_model(model_id, question):
|
| 12 |
model, tokenizer = load_model_and_tokenizer(model_id)
|
| 13 |
-
inputs = tokenizer
|
| 14 |
-
outputs = model.generate(inputs, max_new_tokens=
|
| 15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
"FinGPT": "second-state/FinGPT-MT-Llama-3-8B-LoRA-GGUF",
|
| 19 |
-
"InvestLM": "yixuantt/InvestLM-mistral-AWQ",
|
| 20 |
-
"FinLlama": "roma2025/FinLlama-3-8B"
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
st.title("💼 Financial LLM Evaluation Interface")
|
| 24 |
|
| 25 |
model_choice = st.selectbox("Select a Financial Model", list(model_map.keys()))
|
| 26 |
-
user_question = st.text_area("Enter your financial question:", "What is
|
| 27 |
|
| 28 |
if st.button("Get Response"):
|
| 29 |
with st.spinner("Generating response..."):
|
|
@@ -33,4 +43,3 @@ if st.button("Get Response"):
|
|
| 33 |
st.write(answer)
|
| 34 |
except Exception as e:
|
| 35 |
st.error(f"Something went wrong: {e}")
|
| 36 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
from huggingface_hub import login
|
| 4 |
import torch
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
|
| 8 |
+
# Set model map
|
| 9 |
+
model_map = {
|
| 10 |
+
"FinGPT": "AI4Finance/FinGPT",
|
| 11 |
+
"FinanceConnect": "ceadar-ie/FinanceConnect-13B",
|
| 12 |
+
"Sujet-Finance": "sujet-ai/Sujet-Finance-8B-v0.1"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# Cache model loading for performance
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model_and_tokenizer(model_id):
|
| 18 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 19 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 20 |
+
model_id,
|
| 21 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 22 |
+
)
|
| 23 |
return model, tokenizer
|
| 24 |
|
| 25 |
+
# Query model
|
| 26 |
def query_model(model_id, question):
|
| 27 |
model, tokenizer = load_model_and_tokenizer(model_id)
|
| 28 |
+
inputs = tokenizer(question, return_tensors="pt")
|
| 29 |
+
outputs = model.generate(**inputs, max_new_tokens=150)
|
| 30 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
|
| 32 |
+
# Streamlit app layout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
st.title("💼 Financial LLM Evaluation Interface")
|
| 34 |
|
| 35 |
model_choice = st.selectbox("Select a Financial Model", list(model_map.keys()))
|
| 36 |
+
user_question = st.text_area("Enter your financial question:", "What is EBITDA?")
|
| 37 |
|
| 38 |
if st.button("Get Response"):
|
| 39 |
with st.spinner("Generating response..."):
|
|
|
|
| 43 |
st.write(answer)
|
| 44 |
except Exception as e:
|
| 45 |
st.error(f"Something went wrong: {e}")
|
|
|