Abs6187 commited on
Commit
89ddcac
1 Parent(s): 0f76627

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -1,30 +1,25 @@
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
- # Load the tokenizer and model from local files
5
  @st.cache_resource
6
  def load_model():
7
- tokenizer = AutoTokenizer.from_pretrained("./", config="config.json")
8
- model = AutoModelForCausalLM.from_pretrained("./")
 
9
  return tokenizer, model
10
 
11
- # Initialize the model and tokenizer
12
- tokenizer, model = load_model()
13
-
14
- # Set up Streamlit page configuration
15
  st.set_page_config(page_title="Legal AI Chatbot", layout="centered")
16
-
17
  st.title("Legal AI Chatbot")
18
- st.write("This chatbot provides responses based on a legal language model.")
19
 
20
- # User input
21
- user_input = st.text_input("Enter your query:")
 
 
22
 
 
 
23
  if user_input:
24
- # Tokenize and generate response
25
- inputs = tokenizer.encode(user_input, return_tensors="pt")
26
- outputs = model.generate(inputs, max_length=150, num_return_sequences=1)
27
-
28
- # Decode and display the output
29
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
30
  st.text_area("Response:", response, height=200)
 
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
 
4
  @st.cache_resource
5
  def load_model():
6
+ model_dir = "./" # Ensure all files, including `vocab.txt`, are in this directory
7
+ tokenizer = AutoTokenizer.from_pretrained(model_dir)
8
+ model = AutoModelForCausalLM.from_pretrained(model_dir)
9
  return tokenizer, model
10
 
 
 
 
 
11
  st.set_page_config(page_title="Legal AI Chatbot", layout="centered")
 
12
  st.title("Legal AI Chatbot")
 
13
 
14
+ st.write("Interact with a legal AI chatbot powered by transformers.")
15
+
16
+ # Load tokenizer and model
17
+ tokenizer, model = load_model()
18
 
19
+ # User input for chatbot
20
+ user_input = st.text_input("Enter your legal query:")
21
  if user_input:
22
+ inputs = tokenizer(user_input, return_tensors="pt")
23
+ outputs = model.generate(inputs["input_ids"], max_length=150)
 
 
 
24
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
25
  st.text_area("Response:", response, height=200)