Spaces:
Sleeping
Sleeping
Download app.py from OGNINJA2221/Roblox_NPC_Chat: direct link, hf CLI and curl.
- Browser
- Download file 969 Bytes
-
https://huggingface.co/spaces/OGNINJA2221/Roblox_NPC_Chat/resolve/main/app.py
- Command line
-
hf download hf://spaces/OGNINJA2221/Roblox_NPC_Chat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/OGNINJA2221/Roblox_NPC_Chat/resolve/main/app.py
969 Bytes
| # app.py | |
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| # Model choice | |
| model_name = "microsoft/DialoGPT-small" | |
| # Load tokenizer and model (will download on first run) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| # Chat function | |
| def chat(input_text): | |
| if not input_text: | |
| return "" | |
| inputs = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt") | |
| reply_ids = model.generate(inputs, max_length=200, pad_token_id=tokenizer.eos_token_id) | |
| reply = tokenizer.decode(reply_ids[:, inputs.shape[-1]:][0], skip_special_tokens=True) | |
| return reply | |
| # Gradio Interface (gr.Interface exposes the /run/predict endpoint) | |
| iface = gr.Interface(fn=chat, inputs="text", outputs="text") | |
| # IMPORTANT: disable SSR so the API endpoint is available to external POSTs | |
| iface.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False) | |