Spaces:
Running
Running
File size: 1,407 Bytes
c2d8087 |
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 35 36 37 |
import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
@st.cache_resource
def load_model_and_tokenizer(model_id):
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
return model, tokenizer
def query_model(model_id, question):
model, tokenizer = load_model_and_tokenizer(model_id)
inputs = tokenizer.encode(question, return_tensors="pt")
outputs = model.generate(inputs, max_new_tokens=100)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
model_map = {
"FinGPT": "second-state/FinGPT-MT-Llama-3-8B-LoRA-GGUF",
"InvestLM": "yixuantt/InvestLM-mistral-AWQ",
"FinLlama": "roma2025/FinLlama-3-8B"
}
st.title("💼 Financial LLM Evaluation Interface")
model_choice = st.selectbox("Select a Financial Model", list(model_map.keys()))
user_question = st.text_area("Enter your financial question:", "What is the market outlook for the next quarter?")
if st.button("Get Response"):
with st.spinner("Generating response..."):
try:
answer = query_model(model_map[model_choice], user_question)
st.subheader(f"Response from {model_choice}:")
st.write(answer)
except Exception as e:
st.error(f"Something went wrong: {e}")
|