Spaces:
Sleeping
Sleeping
Download app.py from Mike369williams/Sanchari-demo: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/spaces/Mike369williams/Sanchari-demo/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mike369williams/Sanchari-demo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mike369williams/Sanchari-demo/resolve/main/app.py
855 Bytes
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| # Your fine-tuned model | |
| model_id = "Mike369williams/sanchari-gpt2-finetuned" | |
| # Load tokenizer and model | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id) | |
| # Chat function | |
| def chat(prompt): | |
| inputs = tokenizer(prompt, return_tensors="pt") | |
| output = model.generate( | |
| **inputs, | |
| max_new_tokens=80, | |
| do_sample=True, | |
| temperature=0.8, | |
| top_p=0.9 | |
| ) | |
| reply = tokenizer.decode(output[0], skip_special_tokens=True) | |
| return reply | |
| # UI | |
| ui = gr.Interface( | |
| fn=chat, | |
| inputs=gr.Textbox(label="Your prompt"), | |
| outputs=gr.Textbox(label="Sanchari Response"), | |
| title="Sanchari — AI Demo", | |
| description="Demo of the fine-tuned Sanchari GPT-2 model." | |
| ) | |
| ui.launch() |