CCockrum commited on
Commit
39ae770
Β·
verified Β·
1 Parent(s): 42a0358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -12,6 +12,13 @@ from langchain_core.output_parsers import StrOutputParser
12
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
13
  from langdetect import detect
14
 
 
 
 
 
 
 
 
15
  # βœ… Device setup
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
  print(f"βœ… Using device: {device}")
@@ -31,12 +38,13 @@ st.set_page_config(page_title="HAL - NASA ChatBot", page_icon="πŸš€")
31
  if "chat_history" not in st.session_state:
32
  st.session_state.chat_history = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
33
 
34
- # βœ… Switched to Flan-T5 Model
35
- MODEL_ID = "google/flan-t5-large"
 
 
 
 
36
 
37
- tokenizer = AutoTokenizer.from_pretrained(model_id)
38
- model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
39
- pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
40
 
41
  llm = HuggingFacePipeline(pipeline=pipe)
42
 
 
12
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
13
  from langdetect import detect
14
 
15
+ # βœ… Switched to Flan-T5 Model
16
+ MODEL_ID = "google/flan-t5-large"
17
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
18
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
19
+ pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
20
+
21
+
22
  # βœ… Device setup
23
  device = "cuda" if torch.cuda.is_available() else "cpu"
24
  print(f"βœ… Using device: {device}")
 
38
  if "chat_history" not in st.session_state:
39
  st.session_state.chat_history = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
40
 
41
+ def load_local_llm(model_id):
42
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
43
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
44
+ return pipeline("text2text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
45
+
46
+
47
 
 
 
 
48
 
49
  llm = HuggingFacePipeline(pipeline=pipe)
50