Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,18 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
from transformers import AutoTokenizer, TextStreamer
|
| 4 |
|
| 5 |
# Load the model and tokenizer
|
| 6 |
-
model_name = "Rafay17/Llama3.
|
| 7 |
-
model
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
labeled_prompt = f"User Input: {message}\nResponse:"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return_tensors="pt",
|
| 19 |
-
padding=True,
|
| 20 |
-
truncation=True,
|
| 21 |
-
max_length=512,
|
| 22 |
-
).to("cuda")
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
response = ""
|
| 27 |
-
for token in model.generate(
|
| 28 |
-
input_ids=inputs.input_ids,
|
| 29 |
-
attention_mask=inputs.attention_mask,
|
| 30 |
-
streamer=text_streamer,
|
| 31 |
-
max_new_tokens=max_tokens,
|
| 32 |
-
temperature=temperature,
|
| 33 |
-
top_p=top_p,
|
| 34 |
-
pad_token_id=tokenizer.eos_token_id,
|
| 35 |
-
):
|
| 36 |
-
response += token
|
| 37 |
-
|
| 38 |
-
return response
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
# Define the Gradio interface
|
| 42 |
-
demo = gr.Interface(
|
| 43 |
-
fn=generate_response,
|
| 44 |
-
inputs=[
|
| 45 |
-
gr.Textbox(lines=2, placeholder="Enter your message here..."),
|
| 46 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 47 |
-
gr.Slider(minimum=1, maximum=512, value=64, label="Max new tokens"),
|
| 48 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature"),
|
| 49 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="Top-p (nucleus sampling)"),
|
| 50 |
-
],
|
| 51 |
-
outputs=gr.Textbox(label="Chatbot Response"),
|
| 52 |
-
live=True
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
if __name__ == "__main__":
|
| 56 |
-
demo.launch()
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
|
|
|
| 3 |
|
| 4 |
# Load the model and tokenizer
|
| 5 |
+
model_name = "Rafay17/Llama3.2_1b_customModle2"
|
| 6 |
+
model = AutoModel.from_pretrained(model_name)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
# Prepare your input text
|
| 10 |
+
input_text = "Your input text goes here."
|
| 11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
|
|
|
| 12 |
|
| 13 |
+
# Forward pass to get model outputs
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
outputs = model(**inputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Do something with the outputs
|
| 18 |
+
print(outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|