Spaces:
Running
Running
Main application
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
|
9 |
+
return model, tokenizer
|
10 |
+
|
11 |
+
def query_model(model_id, question):
|
12 |
+
model, tokenizer = load_model_and_tokenizer(model_id)
|
13 |
+
inputs = tokenizer.encode(question, return_tensors="pt")
|
14 |
+
outputs = model.generate(inputs, max_new_tokens=100)
|
15 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
model_map = {
|
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 the market outlook for the next quarter?")
|
27 |
+
|
28 |
+
if st.button("Get Response"):
|
29 |
+
with st.spinner("Generating response..."):
|
30 |
+
try:
|
31 |
+
answer = query_model(model_map[model_choice_
|