Spaces:
Runtime error
Runtime error
Download app_old.py from Replicable/SEYFOR_ALPHA: direct link, hf CLI and curl.
- Browser
- Download file 835 Bytes
-
https://huggingface.co/spaces/Replicable/SEYFOR_ALPHA/resolve/main/app_old.py
- Command line
-
hf download hf://spaces/Replicable/SEYFOR_ALPHA/app_old.py
-
curl -L -o app_old.py https://huggingface.co/spaces/Replicable/SEYFOR_ALPHA/resolve/main/app_old.py
835 Bytes
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| # Načtení modelu | |
| MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf" # Změň podle potřeby | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_NAME, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| # Funkce pro generování textu | |
| def chat(prompt): | |
| inputs = tokenizer(prompt, return_tensors="pt").to("cuda") | |
| output = model.generate(**inputs, max_new_tokens=100) | |
| return tokenizer.decode(output[0], skip_special_tokens=True) | |
| # Webové UI pomocí Gradio | |
| interface = gr.Interface( | |
| fn=chat, | |
| inputs="text", | |
| outputs="text", | |
| title="LLaMA 2 Chatbot", | |
| description="Tento chatbot běží na modelu LLaMA 2 a odpovídá na otázky.", | |
| ) | |
| interface.launch() |