Commit ·
8332f7a
1
Parent(s): 70feffe
Change model
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def initialize_model():
|
|
| 32 |
# Access token might be needed for some models
|
| 33 |
# token = huggingface_hub.get_token()
|
| 34 |
|
| 35 |
-
model_name = "
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 37 |
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
model_name,
|
|
@@ -40,7 +40,7 @@ def initialize_model():
|
|
| 40 |
device_map="auto",
|
| 41 |
trust_remote_code=True
|
| 42 |
)
|
| 43 |
-
logger.info("Successfully initialized
|
| 44 |
return model, tokenizer
|
| 45 |
except Exception as e:
|
| 46 |
logger.exception("Error initializing Hugging Face model.")
|
|
@@ -54,7 +54,7 @@ model, tokenizer = initialize_model()
|
|
| 54 |
###############################################################################
|
| 55 |
def generate_with_model(prompt, max_length=1400, temperature=0.3):
|
| 56 |
"""Generate text using the Hugging Face model."""
|
| 57 |
-
logger.info("Generating text with
|
| 58 |
|
| 59 |
try:
|
| 60 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
|
|
|
| 32 |
# Access token might be needed for some models
|
| 33 |
# token = huggingface_hub.get_token()
|
| 34 |
|
| 35 |
+
model_name = "microsoft/phi-2"
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 37 |
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
model_name,
|
|
|
|
| 40 |
device_map="auto",
|
| 41 |
trust_remote_code=True
|
| 42 |
)
|
| 43 |
+
logger.info("Successfully initialized phi-2 model and tokenizer.")
|
| 44 |
return model, tokenizer
|
| 45 |
except Exception as e:
|
| 46 |
logger.exception("Error initializing Hugging Face model.")
|
|
|
|
| 54 |
###############################################################################
|
| 55 |
def generate_with_model(prompt, max_length=1400, temperature=0.3):
|
| 56 |
"""Generate text using the Hugging Face model."""
|
| 57 |
+
logger.info("Generating text with phi-2 model.")
|
| 58 |
|
| 59 |
try:
|
| 60 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|