Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
7 |
|
8 |
# Define the system message for the model
|
9 |
-
system_message =
|
10 |
-
"
|
11 |
-
"
|
12 |
-
|
|
|
13 |
|
14 |
# Function to reset the chat
|
15 |
def reset_chat():
|
@@ -45,22 +49,16 @@ def chat(user_input, messages):
|
|
45 |
# Append user message to the conversation history
|
46 |
messages.append({"role": "user", "content": user_input})
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
try:
|
49 |
-
# Generate a response from the
|
50 |
-
|
51 |
-
|
52 |
-
messages=messages,
|
53 |
-
temperature=1,
|
54 |
-
max_tokens=1024,
|
55 |
-
top_p=1,
|
56 |
-
stream=False,
|
57 |
-
)
|
58 |
-
|
59 |
-
# Ensure response is valid
|
60 |
-
if completion.choices and len(completion.choices) > 0:
|
61 |
-
response_content = completion.choices[0].message.content
|
62 |
-
else:
|
63 |
-
response_content = "Sorry, I couldn't generate a response."
|
64 |
|
65 |
except Exception as e:
|
66 |
response_content = f"Error: {str(e)}"
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import torch
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
6 |
+
# Load the model and tokenizer
|
7 |
+
model_name = "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
|
11 |
# Define the system message for the model
|
12 |
+
system_message = (
|
13 |
+
"You are an experienced Fashion designer who starts conversation with proper greeting, "
|
14 |
+
"giving valuable and catchy fashion advice and suggestions, stays to the point and precise, "
|
15 |
+
"asks questions only if the user has any concerns over your provided suggestions."
|
16 |
+
)
|
17 |
|
18 |
# Function to reset the chat
|
19 |
def reset_chat():
|
|
|
49 |
# Append user message to the conversation history
|
50 |
messages.append({"role": "user", "content": user_input})
|
51 |
|
52 |
+
# Prepare the input for the model
|
53 |
+
input_text = system_message + "\n" + "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
54 |
+
|
55 |
+
# Tokenize and encode the input text
|
56 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
57 |
+
|
58 |
try:
|
59 |
+
# Generate a response from the model
|
60 |
+
outputs = model.generate(**inputs, max_length=150, num_return_sequences=1, temperature=0.7)
|
61 |
+
response_content = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
except Exception as e:
|
64 |
response_content = f"Error: {str(e)}"
|