File size: 1,575 Bytes
94a65e4
 
 
 
 
 
 
 
 
30c7f0c
94a65e4
 
 
 
 
 
 
 
 
 
 
 
30c7f0c
94a65e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30c7f0c
94a65e4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# import requests
# import json

# # Replace with your actual Hugging Face Spaces URL
# SPACE_API_URL = "https://heheboi0769-nexus-nlp-model.hf.space//?text=Breaking: Stock market crashes!"

# # Add the text as a query parameter since the app uses st.experimental_get_query_params()
# text = "Breaking: Stock market crashes!"
# url_with_params = f"{SPACE_API_URL}?text={text}"

# # Send request to Streamlit API
# response = requests.get(url_with_params)

# # Parse JSON response
# if response.status_code == 200:
#     result = response.json()
#     print(f"Prediction: {result['prediction']} (Confidence: {result['confidence']*100:.2f}%)")
# else:
#     print("Error: Could not get prediction")

import requests
import urllib.parse

def test_model():
    # Base URL for your Streamlit app
    base_url = "https://heheboi0769-nexus-nlp-model.hf.space/api"
    
    # Test text
    text = "Breaking: Stock market crashes!"
    
    # Make request to the Streamlit app's API endpoint
    response = requests.post(
        f"{base_url}/predict",
        headers={
            "Content-Type": "application/json",
            "Authorization": "Bearer your_api_key_here"
        },
        json={"text": text}
    )
    
    # Print response for debugging
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.text}")
    
    if response.status_code == 200:
        result = response.json()
        print(f"Prediction: {result['prediction']}")
        print(f"Confidence: {result['confidence']*100:.2f}%")

if __name__ == "__main__":
    test_model()