Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|