4lli39421 commited on
Commit
c2d8087
·
verified ·
1 Parent(s): 69f8bb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -31
app.py CHANGED
@@ -1,31 +1,36 @@
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_
 
 
 
 
 
 
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], user_question)
32
+ st.subheader(f"Response from {model_choice}:")
33
+ st.write(answer)
34
+ except Exception as e:
35
+ st.error(f"Something went wrong: {e}")
36
+