pravjet commited on
Commit
0565ab0
·
verified ·
1 Parent(s): 3b7e333

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -18,7 +18,6 @@ verdict_counts = {"Authentic": 0, "Possibly Misinformation": 0}
18
  # API keys
19
  FACT_CHECK_API_KEY = os.getenv("FACT_CHECK_API_KEY")
20
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
21
- openai.api_key = OPENAI_API_KEY
22
 
23
  def extract_text_from_url(url):
24
  try:
@@ -71,7 +70,8 @@ def gpt_fact_check(prompt):
71
  if not OPENAI_API_KEY:
72
  return "OpenAI API key not found. Please set OPENAI_API_KEY in environment."
73
  try:
74
- response = openai.ChatCompletion.create(
 
75
  model="gpt-3.5-turbo", # or "gpt-4" if you have access
76
  messages=[
77
  {"role": "system", "content": "You are a helpful assistant for fact-checking news articles. Analyze the following content for misinformation, summarize the main claim, and explain your reasoning."},
@@ -80,7 +80,7 @@ def gpt_fact_check(prompt):
80
  max_tokens=300,
81
  temperature=0.2,
82
  )
83
- return response['choices'][0]['message']['content'].strip()
84
  except Exception as e:
85
  return f"OpenAI API error: {e}"
86
 
@@ -132,4 +132,4 @@ with gr.Blocks() as demo:
132
  outputs=[output_text, verdict, score, chart, fact_check, gpt_fact]
133
  )
134
 
135
- demo.launch()
 
18
  # API keys
19
  FACT_CHECK_API_KEY = os.getenv("FACT_CHECK_API_KEY")
20
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 
21
 
22
  def extract_text_from_url(url):
23
  try:
 
70
  if not OPENAI_API_KEY:
71
  return "OpenAI API key not found. Please set OPENAI_API_KEY in environment."
72
  try:
73
+ client = openai.OpenAI(api_key=OPENAI_API_KEY)
74
+ response = client.chat.completions.create(
75
  model="gpt-3.5-turbo", # or "gpt-4" if you have access
76
  messages=[
77
  {"role": "system", "content": "You are a helpful assistant for fact-checking news articles. Analyze the following content for misinformation, summarize the main claim, and explain your reasoning."},
 
80
  max_tokens=300,
81
  temperature=0.2,
82
  )
83
+ return response.choices[0].message.content.strip()
84
  except Exception as e:
85
  return f"OpenAI API error: {e}"
86
 
 
132
  outputs=[output_text, verdict, score, chart, fact_check, gpt_fact]
133
  )
134
 
135
+ demo.launch()