Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,43 +4,29 @@ from peft import PeftModel # Ensure PEFT is installed: pip install peft
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
# Define the model and base paths
|
| 7 |
-
|
| 8 |
-
base_model = "google/gemma-2b"
|
| 9 |
|
| 10 |
-
# Use your Hugging Face token
|
| 11 |
-
hf_token = os.getenv('HF_TOKEN')
|
| 12 |
|
| 13 |
-
# Load tokenizer with authentication
|
| 14 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model, token=hf_token, force_download=True)
|
| 15 |
|
| 16 |
-
# Load the base model and apply adapter with authentication
|
| 17 |
-
base_model = AutoModelForCausalLM.from_pretrained(base_model, device_map="auto", token=hf_token)
|
| 18 |
-
model = PeftModel.from_pretrained(base_model, model_path)
|
| 19 |
|
| 20 |
|
| 21 |
# Create pipeline
|
| 22 |
-
pipe = pipeline(
|
| 23 |
-
"text-generation",
|
| 24 |
-
model=model,
|
| 25 |
-
tokenizer=tokenizer,
|
| 26 |
-
device=0 # Assuming GPU is available
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
def predict(input_text
|
| 30 |
-
|
| 31 |
-
prompt = f"{system_message}\nUser: {input_text}\nAssistant:"
|
| 32 |
-
|
| 33 |
-
# Generate text using the pipeline
|
| 34 |
-
result = pipe(
|
| 35 |
-
prompt,
|
| 36 |
-
max_length=max_new_tokens,
|
| 37 |
-
temperature=temperature,
|
| 38 |
-
top_p=top_p,
|
| 39 |
-
num_return_sequences=1
|
| 40 |
-
)
|
| 41 |
generated_text = result[0]["generated_text"]
|
| 42 |
return generated_text
|
| 43 |
|
|
|
|
| 44 |
# Create the Gradio interface
|
| 45 |
demo = gr.Interface(
|
| 46 |
fn=predict,
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
# Define the model and base paths
|
| 7 |
+
model = "FadQ/gemma-2b-diary-consultaton-chatbot"
|
| 8 |
+
# base_model = "google/gemma-2b"
|
| 9 |
|
| 10 |
+
# # Use your Hugging Face token
|
| 11 |
+
# hf_token = os.getenv('HF_TOKEN')
|
| 12 |
|
| 13 |
+
# # Load tokenizer with authentication
|
| 14 |
+
# tokenizer = AutoTokenizer.from_pretrained(base_model, token=hf_token, force_download=True)
|
| 15 |
|
| 16 |
+
# # Load the base model and apply adapter with authentication
|
| 17 |
+
# base_model = AutoModelForCausalLM.from_pretrained(base_model, device_map="auto", token=hf_token)
|
| 18 |
+
# model = PeftModel.from_pretrained(base_model, model_path)
|
| 19 |
|
| 20 |
|
| 21 |
# Create pipeline
|
| 22 |
+
pipe = pipeline("text-generation", model=model_path, device=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
def predict(input_text):
|
| 25 |
+
result = pipe(input_text, max_length=150, num_return_sequences=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
generated_text = result[0]["generated_text"]
|
| 27 |
return generated_text
|
| 28 |
|
| 29 |
+
|
| 30 |
# Create the Gradio interface
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=predict,
|