Spaces:
Sleeping
Sleeping
Loomisgitarrist commited on
Commit ·
cee25f3
1
Parent(s): 071b992
Deploy Flan-T5 Docker with FastAPI Standard
Browse files- test_hf_api.py +33 -0
- verify_model.py +13 -0
test_hf_api.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
# The URL of your Hugging Face Space
|
| 5 |
+
# Note: Hugging Face converts usernames and space names to lowercase for the URL.
|
| 6 |
+
API_URL = "https://loomisgitarrist-personal-coder-ai.hf.space/ask"
|
| 7 |
+
|
| 8 |
+
def test_api():
|
| 9 |
+
print(f"Testing API at: {API_URL}")
|
| 10 |
+
prompt = "Translate to German: This is a test of the deployed API."
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
print(f"Sending prompt: '{prompt}'...")
|
| 14 |
+
response = requests.get(API_URL, params={"prompt": prompt}, timeout=30)
|
| 15 |
+
|
| 16 |
+
if response.status_code == 200:
|
| 17 |
+
data = response.json()
|
| 18 |
+
print("\n✅ Success!")
|
| 19 |
+
print(f"Response: {data}")
|
| 20 |
+
# The model returns a list with 'generated_text' usually, but our app.py returns result[0]
|
| 21 |
+
# so it should look like {'generated_text': 'Dies ist ein Test...'}
|
| 22 |
+
else:
|
| 23 |
+
print(f"\n❌ Error: Status Code {response.status_code}")
|
| 24 |
+
print(f"Details: {response.text}")
|
| 25 |
+
|
| 26 |
+
except requests.exceptions.ConnectionError:
|
| 27 |
+
print("\n❌ Connection Error: The Space might still be building or sleeping.")
|
| 28 |
+
print("Check the build status on Hugging Face: https://huggingface.co/spaces/Loomisgitarrist/personal-coder-ai")
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"\n❌ An error occurred: {e}")
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
test_api()
|
verify_model.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
print("Loading model...")
|
| 5 |
+
start_time = time.time()
|
| 6 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
+
end_time = time.time()
|
| 8 |
+
print(f"Model loaded in {end_time - start_time:.2f} seconds.")
|
| 9 |
+
|
| 10 |
+
prompt = "Translate to German: Hello, how are you?"
|
| 11 |
+
print(f"Running inference on: '{prompt}'")
|
| 12 |
+
result = pipe(prompt)
|
| 13 |
+
print(f"Result: {result[0]['generated_text']}")
|