TejAndrewsACC commited on
Commit
beda908
·
verified ·
1 Parent(s): 4d9ef3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -1,14 +1,25 @@
 
1
  import gradio as gr
2
  import os
3
 
4
- # Set your Hugging Face token as an environment variable (recommended for security)
5
- hf_token = os.getenv("DOWNLOAD") # Make sure to set HF_TOKEN in your environment
 
6
 
7
- if not hf_token:
8
- raise ValueError("Rejected...")
 
9
 
10
- # Load the model using Gradio and the token
11
- interface = gr.load("huggingface/meta-llama/Llama-3.3-70B-Instruct", api_key=hf_token)
12
 
13
- # Launch the Gradio interface
 
 
 
 
 
 
 
 
14
  interface.launch()
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
  import gradio as gr
3
  import os
4
 
5
+ # Hugging Face model and token
6
+ model_name = "meta-llama/Llama-3.3-70B-Instruct"
7
+ hf_token = os.getenv("DOWNLOAD")
8
 
9
+ # Load model and tokenizer
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
11
+ model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
12
 
13
+ # System message
14
+ system_message = "You are a helpful assistant. Always provide clear and concise responses."
15
 
16
+ # Chat function
17
+ def chat(user_input):
18
+ prompt = f"{system_message}\n\nUser: {user_input}\nAssistant:"
19
+ inputs = tokenizer(prompt, return_tensors="pt")
20
+ outputs = model.generate(**inputs, max_new_tokens=150)
21
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+
23
+ # Gradio interface
24
+ interface = gr.Interface(fn=chat, inputs="text", outputs="text")
25
  interface.launch()