Nexus_NLP_model / test.py
Krish Patel
Added gemini analysis and knowledge graph
94a65e4
# 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()