Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
import requests | |
# retrieve HF space secrets | |
auth_key = os.getenv('AUTH_KEY') | |
api_url = os.getenv('API_URL') | |
api_port = os.getenv('API_PORT') | |
HEADERS = { | |
'Content-Type': 'application/json' | |
} | |
def news_analysis(text): | |
try: | |
response = requests.post( | |
f'{api_url}:{api_port}/news_analysis', | |
json={ | |
'doc_id': '1', | |
'text': text, | |
'auth_key': auth_key | |
}, | |
headers=HEADERS | |
) | |
response.raise_for_status() | |
return response.json() | |
except requests.exceptions.RequestException as error: | |
print('Error fetching data from news_analysis:', error) | |
raise | |
def claim_verification(text): | |
try: | |
response = requests.post( | |
f'{api_url}:{api_port}/claim_verification', | |
json={ | |
'doc_id': '1', | |
'text': text, | |
'auth_key': auth_key | |
}, | |
headers=HEADERS | |
) | |
response.raise_for_status() | |
return response.json() | |
except requests.exceptions.RequestException as error: | |
print('Error fetching data from claim_verification:', error) | |
raise | |
iface_news_analysis = gr.Interface( | |
fn=news_analysis, | |
inputs=gr.inputs.Textbox(lines=10, label="News Article Text"), | |
outputs=gr.outputs.JSON(label="Classification Result"), | |
title="News Analysis", | |
description="Classify the domain of a news article and detect major claims." | |
) | |
iface_claim_verification = gr.Interface( | |
fn=claim_verification, | |
inputs=gr.inputs.Textbox(lines=10, label="Claim Text"), | |
outputs=gr.outputs.JSON(label="Verification Result"), | |
title="Claim Verification", | |
description="Verify claims made in a news article." | |
) | |
iface = gr.TabbedInterface([iface_news_analysis, iface_claim_verification], ["News Analysis", "Claim Verification"]) | |
# launch the interface | |
iface.launch(server_name="0.0.0.0", server_port=7860) |