desinez's picture
Fix internal service API base routing for Hugging Face network interface
7f62ff3
Raw History Blame Contribute Delete
1.15 kB
import requests
import os
# Dynamically pull the port from the environment (will be 7860 on Hugging Face)
# or fall back to 8000 if you run it locally.
PORT = os.environ.get("PORT", "8000")
BASE_URL = f"http://127.0.0.1:{PORT}"
class PvRecNetAPI:
@staticmethod
def upload_dataset(file_bytes, filename):
files = {'file': (filename, file_bytes, 'text/csv')}
response = requests.post(f"{BASE_URL}/upload-data", files=files)
response.raise_for_status()
return response.json()
@staticmethod
def run_prediction(dataset_id):
response = requests.post(f"{BASE_URL}/predict", json={"dataset_id": dataset_id})
response.raise_for_status()
return response.json()
@staticmethod
def get_moi(dataset_id):
response = requests.post(f"{BASE_URL}/compute-moi", json={"dataset_id": dataset_id})
response.raise_for_status()
return response.json()
@staticmethod
def get_allele_freq(dataset_id):
response = requests.post(f"{BASE_URL}/allele-frequency", json={"dataset_id": dataset_id})
response.raise_for_status()
return response.json()