Download app.py from oguz0126/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 979 Bytes
-
https://huggingface.co/spaces/oguz0126/chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/oguz0126/chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/oguz0126/chatbot/resolve/main/app.py
979 Bytes
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| MODEL_NAME = "facebook/xglm-564M" | |
| # Slow tokenizer kullanımı | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=False) # HATA BÖYLE ÇÖZÜLÜYOR | |
| model = AutoModelForCausalLM.from_pretrained(MODEL_NAME) | |
| generator = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| max_new_tokens=100, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_p=0.9, | |
| repetition_penalty=1.1, | |
| ) | |
| def chat_with_xglm(prompt): | |
| yeni_istem = f"Kullanıcı: {prompt}\nAsistan:" | |
| output = generator(yeni_istem)[0]["generated_text"].split("Asistan:")[-1] | |
| return output.strip() | |
| demo = gr.Interface( | |
| fn=chat_with_xglm, | |
| inputs="text", | |
| outputs="text", | |
| title="XGLM-564M Çok Dilli Chatbot", | |
| description="Bu model Türkçe ve Fransızca metin üretmek için eğitilmiştir." | |
| ) | |
| def main(): | |
| demo.launch() | |
| if __name__ == "__main__": | |
| main() |