Spaces:
Runtime error
Runtime error
Download app.py from gampala1234/chat: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/gampala1234/chat/resolve/3dadeb536eed1d9a79f4ed98dba94de054e213dc/app.py
- Command line
-
hf download hf://spaces/gampala1234/chat@3dadeb536eed1d9a79f4ed98dba94de054e213dc/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gampala1234/chat/resolve/3dadeb536eed1d9a79f4ed98dba94de054e213dc/app.py
1.32 kB
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| # Load the model and tokenizer | |
| model_id = "Qwen/Qwen3-0.6B" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32) | |
| def chat(message, history): | |
| # Format the history in the new messages format | |
| messages = [] | |
| for user_msg, bot_msg in history: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": bot_msg}) | |
| messages.append({"role": "user", "content": message}) | |
| # Prepare input for the model | |
| inputs = tokenizer(message, return_tensors="pt") | |
| outputs = model.generate( | |
| inputs["input_ids"], | |
| attention_mask=inputs["attention_mask"], | |
| max_new_tokens=150, | |
| do_sample=True, | |
| top_p=0.9, | |
| temperature=0.7 | |
| ) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return response | |
| # Create the chat interface with the new messages format | |
| demo = gr.ChatInterface( | |
| fn=chat, | |
| title="Maya AI (Lite)", | |
| theme="soft", | |
| # Updated Chatbot configuration without the invalid 'likeable' parameter | |
| chatbot=gr.Chatbot(height=500, layout="panel", type="messages") | |
| ) | |
| demo.launch() |