metek7 commited on
Commit
bda0689
·
verified ·
1 Parent(s): 5c467b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -1,3 +1,34 @@
1
  import gradio as gr
 
 
 
2
 
3
- gr.load("models/meta-llama/Meta-Llama-3.1-8B").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+ from huggingface_hub import login
5
 
6
+ # Hugging Face hesabınıza giriş yapın
7
+ login(token="your_huggingface_token_here")
8
+
9
+ # Doğru model adını kullanın
10
+ model_name = "meta-llama/Llama-2-7b-hf" # veya kullanmak istediğiniz LLaMA modelinin doğru adı
11
+
12
+ # Model ve tokenizer'ı yükleyin
13
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
14
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto", use_auth_token=True)
15
+
16
+ def generate_text(prompt, max_length=100):
17
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
18
+ outputs = model.generate(**inputs, max_length=max_length)
19
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
20
+
21
+ # Gradio arayüzünü oluşturun
22
+ iface = gr.Interface(
23
+ fn=generate_text,
24
+ inputs=[
25
+ gr.Textbox(lines=3, label="Prompt"),
26
+ gr.Slider(minimum=10, maximum=500, value=100, step=1, label="Maksimum Uzunluk")
27
+ ],
28
+ outputs=gr.Textbox(label="Üretilen Metin"),
29
+ title="LLaMA Metin Üreteci",
30
+ description="LLaMA modeli kullanarak metin üretin."
31
+ )
32
+
33
+ # Arayüzü başlatın
34
+ iface.launch()