Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch | |
| 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}") | |