Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("your-username/lex-fridman-chatbot")
6model = AutoModelForCausalLM.from_pretrained("your-username/lex-fridman-chatbot")
7
8# Generate response
9def chat_with_lex(question):
10 prompt = f"Human: {question}\n\nLex:"
11 inputs = tokenizer.encode(prompt, return_tensors="pt")
12
13 with torch.no_grad():
14 outputs = model.generate(
15 inputs,
16 max_length=inputs.shape[1] + 100,
17 temperature=0.8,
18 do_sample=True,
19 top_p=0.9,
20 pad_token_id=tokenizer.eos_token_id
21 )
22
23 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
24 return response.split("Lex:")[-1].strip()
25
26# Example usage
27response = chat_with_lex("What do you think about artificial intelligence?")
28print(response)streamlit run web_app/lex_chatbot_app.py1@misc{lex-fridman-chatbot,
2 title={Lex Fridman AI Chatbot},
3 author={Your Name},
4 year={2025},
5 publisher={Hugging Face},
6 url={https://huggingface.co/your-username/lex-fridman-chatbot}
7}