Spaces:
Runtime error
Runtime error
Upload factchecking_front.py
Browse files- factchecking_front.py +8 -48
factchecking_front.py
CHANGED
|
@@ -1,55 +1,15 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import requests
|
| 4 |
-
import time
|
| 5 |
-
|
| 6 |
-
API_URL = "https://Iker-FactChecking-Backend.hf.space:7860" # Replace with your server's URL if different
|
| 7 |
-
API_KEY = os.getenv("API_KEY")
|
| 8 |
-
|
| 9 |
-
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Function to submit a fact-checking request
|
| 13 |
-
def submit_fact_check(article_topic, config):
|
| 14 |
-
endpoint = f"{API_URL}/fact-check"
|
| 15 |
-
payload = {"article_topic": article_topic, "config": config}
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
return response.json()["job_id"]
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Function to get the result of a fact-checking job
|
| 23 |
-
def get_fact_check_result(job_id):
|
| 24 |
-
endpoint = f"{API_URL}/result/{job_id}"
|
| 25 |
|
| 26 |
-
|
| 27 |
-
response.raise_for_status() # Raise an exception for HTTP errors
|
| 28 |
-
return response.json()
|
| 29 |
|
| 30 |
|
| 31 |
def fact_checking(article_topic: str, config="pro"):
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
# Poll for results
|
| 37 |
-
while True:
|
| 38 |
-
result = get_fact_check_result(job_id)
|
| 39 |
-
if result["status"] == "completed":
|
| 40 |
-
print("Fact-checking completed:")
|
| 41 |
-
print(result["result"])
|
| 42 |
-
break
|
| 43 |
-
elif result["status"] == "failed":
|
| 44 |
-
print("Fact-checking failed:")
|
| 45 |
-
print(result["error"])
|
| 46 |
-
break
|
| 47 |
-
else:
|
| 48 |
-
print("Fact-checking in progress. Waiting...")
|
| 49 |
-
time.sleep(2) # Wait for 2 seconds before checking again
|
| 50 |
-
|
| 51 |
-
except requests.exceptions.RequestException as e:
|
| 52 |
-
print(f"An error occurred: {e}")
|
| 53 |
|
| 54 |
return result
|
| 55 |
|
|
@@ -96,7 +56,7 @@ if __name__ == "__main__":
|
|
| 96 |
|
| 97 |
gr_mode = gr.Radio(
|
| 98 |
label="Fact-Checking Mode",
|
| 99 |
-
info=
|
| 100 |
choices=["Pro", "Turbo"],
|
| 101 |
type="value",
|
| 102 |
value="Pro",
|
|
@@ -144,7 +104,7 @@ if __name__ == "__main__":
|
|
| 144 |
|
| 145 |
gr_play.click(
|
| 146 |
fact_checking,
|
| 147 |
-
inputs=[gr_text,gr_mode],
|
| 148 |
outputs=[gr_output, gr_ft, gr_qa, gr_citations, gr_image],
|
| 149 |
)
|
| 150 |
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gradio_client import Client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
client = Client("Iker/FactChecking-Backend")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def fact_checking(article_topic: str, config="pro"):
|
| 10 |
+
result = client.predict(
|
| 11 |
+
article_topic=article_topic, config=config, api_name="/partial"
|
| 12 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
return result
|
| 15 |
|
|
|
|
| 56 |
|
| 57 |
gr_mode = gr.Radio(
|
| 58 |
label="Fact-Checking Mode",
|
| 59 |
+
info='Choose the fact-checking mode. The "Turbo" mode is faster and cheaper. The "Pro" mode is more accurate but more expensive.',
|
| 60 |
choices=["Pro", "Turbo"],
|
| 61 |
type="value",
|
| 62 |
value="Pro",
|
|
|
|
| 104 |
|
| 105 |
gr_play.click(
|
| 106 |
fact_checking,
|
| 107 |
+
inputs=[gr_text, gr_mode],
|
| 108 |
outputs=[gr_output, gr_ft, gr_qa, gr_citations, gr_image],
|
| 109 |
)
|
| 110 |
|