Spaces:
No application file
No application file
Download real AI.py from kian201392/open_AI: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/kian201392/open_AI/resolve/main/real%20AI.py
- Command line
-
hf download 'hf://spaces/kian201392/open_AI/real AI.py'
-
curl -L -o 'real AI.py' https://huggingface.co/spaces/kian201392/open_AI/resolve/main/real%20AI.py
1.04 kB
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch | |
| print("Loading model...") | |
| tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large") | |
| model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large") | |
| print("Model loaded. Type 'exit' to quit.") | |
| chat_history_ids = None | |
| while True: | |
| user_input = input("You: ") | |
| if user_input.lower() == "exit": | |
| break | |
| new_input_ids = tokenizer.encode( | |
| user_input + tokenizer.eos_token, | |
| return_tensors="pt" | |
| ) | |
| if chat_history_ids is None: | |
| bot_input_ids = new_input_ids | |
| else: | |
| bot_input_ids = torch.cat([chat_history_ids, new_input_ids], dim=-1) | |
| chat_history_ids = model.generate( | |
| bot_input_ids, | |
| max_new_tokens=50, | |
| pad_token_id=tokenizer.eos_token_id, | |
| temperature=0.7, | |
| top_p=0.9 | |
| ) | |
| response = tokenizer.decode( | |
| chat_history_ids[0][bot_input_ids.shape[-1]:], | |
| skip_special_tokens=True | |
| ) | |
| print("Bot:", response) |