Replicable commited on
Commit
85d731b
·
verified ·
1 Parent(s): 3a9774f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Načtení modelu
6
+ MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf" # Změň podle potřeby
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ MODEL_NAME,
10
+ torch_dtype=torch.float16,
11
+ device_map="auto"
12
+ )
13
+
14
+ # Funkce pro generování textu
15
+ def chat(prompt):
16
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
17
+ output = model.generate(**inputs, max_new_tokens=100)
18
+ return tokenizer.decode(output[0], skip_special_tokens=True)
19
+
20
+ # Webové UI pomocí Gradio
21
+ interface = gr.Interface(
22
+ fn=chat,
23
+ inputs="text",
24
+ outputs="text",
25
+ title="LLaMA 2 Chatbot",
26
+ description="Tento chatbot běží na modelu LLaMA 2 a odpovídá na otázky.",
27
+ )
28
+
29
+ interface.launch()