Spaces:
Sleeping
Sleeping
Update server.py
Browse fileschanging model to google flan 750m
server.py
CHANGED
|
@@ -15,13 +15,13 @@ optimizer_pipeline = None
|
|
| 15 |
|
| 16 |
# --- Hugging Face Model Loading ---
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
-
model_name = '
|
| 20 |
|
| 21 |
print(f"Loading {model_name} model...")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
hf_task = '
|
| 25 |
|
| 26 |
optimizer_pipeline = pipeline(hf_task, model=model_name)
|
| 27 |
|
|
@@ -34,6 +34,11 @@ except Exception as e_hf:
|
|
| 34 |
|
| 35 |
|
| 36 |
# --- 3. Create an API Endpoint ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
@app.route('/optimize', methods=['POST'])
|
| 38 |
def optimize_code():
|
| 39 |
print("\n--- Received a request ---")
|
|
@@ -81,5 +86,5 @@ def optimize_code():
|
|
| 81 |
|
| 82 |
# --- 4. Run the Server ---
|
| 83 |
if __name__ == '__main__':
|
| 84 |
-
# Listen on 0.0.0.0
|
| 85 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 15 |
|
| 16 |
# --- Hugging Face Model Loading ---
|
| 17 |
try:
|
| 18 |
+
# Use the "large" instruction-tuned model
|
| 19 |
+
model_name = 'google/flan-t5-large'
|
| 20 |
|
| 21 |
print(f"Loading {model_name} model...")
|
| 22 |
|
| 23 |
+
# Use 'text2text-generation' for T5 models
|
| 24 |
+
hf_task = 'text2text-generation'
|
| 25 |
|
| 26 |
optimizer_pipeline = pipeline(hf_task, model=model_name)
|
| 27 |
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
# --- 3. Create an API Endpoint ---
|
| 37 |
+
@app.route('/')
|
| 38 |
+
def home():
|
| 39 |
+
# A simple route to check if the server is alive
|
| 40 |
+
return "Code Optimizer API is running."
|
| 41 |
+
|
| 42 |
@app.route('/optimize', methods=['POST'])
|
| 43 |
def optimize_code():
|
| 44 |
print("\n--- Received a request ---")
|
|
|
|
| 86 |
|
| 87 |
# --- 4. Run the Server ---
|
| 88 |
if __name__ == '__main__':
|
| 89 |
+
# Listen on 0.0.0.0 and port 7860 for Hugging Face Spaces
|
| 90 |
app.run(host='0.0.0.0', port=7860)
|