Update app.py
Browse files
app.py
CHANGED
@@ -142,33 +142,24 @@ def init_db():
|
|
142 |
conn.commit()
|
143 |
|
144 |
def initialize_llm():
|
145 |
-
"""Initialize the
|
146 |
try:
|
147 |
# Get API token
|
148 |
api_token = os.environ.get('HF_TOKEN')
|
149 |
if not api_token:
|
150 |
-
raise ValueError("No
|
151 |
|
152 |
-
#
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=api_token)
|
158 |
-
|
159 |
-
print("Loading model...")
|
160 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=api_token)
|
161 |
-
|
162 |
-
# Test the model with a simple prompt
|
163 |
-
print("Testing the model...")
|
164 |
-
prompt = "Say hello"
|
165 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
166 |
-
outputs = model.generate(**inputs, max_length=50)
|
167 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
168 |
|
169 |
-
|
|
|
|
|
170 |
|
171 |
-
return
|
172 |
|
173 |
except Exception as e:
|
174 |
print(f"LLM initialization error: {str(e)}")
|
|
|
142 |
conn.commit()
|
143 |
|
144 |
def initialize_llm():
|
145 |
+
"""Initialize the model in the simplest way possible"""
|
146 |
try:
|
147 |
# Get API token
|
148 |
api_token = os.environ.get('HF_TOKEN')
|
149 |
if not api_token:
|
150 |
+
raise ValueError("No API token found")
|
151 |
|
152 |
+
# Initialize with minimal settings
|
153 |
+
llm = HuggingFaceHub(
|
154 |
+
repo_id="microsoft/phi-4", # Using a simpler model for testing
|
155 |
+
huggingfacehub_api_token=api_token
|
156 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
+
# Quick test
|
159 |
+
test = llm("Say hello")
|
160 |
+
print(f"Test response: {test}")
|
161 |
|
162 |
+
return llm
|
163 |
|
164 |
except Exception as e:
|
165 |
print(f"LLM initialization error: {str(e)}")
|