Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,16 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
-
#
|
5 |
-
model_name = "meta-llama/Llama-3.2-1B"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# Fetch API token from environment
|
10 |
api_token = os.getenv("Llama_Token")
|
11 |
|
12 |
-
# Authenticate
|
13 |
login(api_token)
|
14 |
|
|
|
|
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=api_token)
|
16 |
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=api_token)
|
17 |
|
@@ -25,9 +24,9 @@ def generate_text(prompt, max_length=100, temperature=0.7):
|
|
25 |
iface = gr.Interface(
|
26 |
fn=generate_text,
|
27 |
inputs=[
|
28 |
-
gr.
|
29 |
-
gr.
|
30 |
-
gr.
|
31 |
],
|
32 |
outputs="text",
|
33 |
title="LLaMA 3.2 Text Generator",
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import login
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
6 |
+
# Fetch API token from environment variable
|
|
|
|
|
|
|
|
|
|
|
7 |
api_token = os.getenv("Llama_Token")
|
8 |
|
9 |
+
# Authenticate with Hugging Face
|
10 |
login(api_token)
|
11 |
|
12 |
+
# Load LLaMA 3.2 model and tokenizer with the API token
|
13 |
+
model_name = "meta-llama/Llama-3.2-1B"
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=api_token)
|
15 |
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=api_token)
|
16 |
|
|
|
24 |
iface = gr.Interface(
|
25 |
fn=generate_text,
|
26 |
inputs=[
|
27 |
+
gr.Textbox(label="Enter your prompt", placeholder="Start typing..."),
|
28 |
+
gr.Slider(minimum=50, maximum=200, default=100, label="Max Length"),
|
29 |
+
gr.Slider(minimum=0.1, maximum=1.0, default=0.7, label="Temperature"),
|
30 |
],
|
31 |
outputs="text",
|
32 |
title="LLaMA 3.2 Text Generator",
|