NKessler commited on
Commit
8140ba1
·
verified ·
1 Parent(s): bb44e6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -5,9 +5,9 @@ import plotly.graph_objects as go
5
  import streamlit as st
6
  from textblob import TextBlob
7
  import json
 
8
  import os
9
  import concurrent.futures
10
- from groq import Groq
11
  import textstat
12
  import trafilatura
13
  import requests
@@ -23,8 +23,11 @@ URL_A = "https://www.foxnews.com/live-news/trump-iran-israel-war-updates-march-3
23
  URL_B = "https://edition.cnn.com/2026/03/30/world/live-news/iran-war-us-israel-trump"
24
 
25
  # Initialize the Hugging Face Client
26
- GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
27
- client = Groq(api_key=GROQ_API_KEY)
 
 
 
28
 
29
  def _truncate_to_words(text: str, limit: int) -> str:
30
  """Truncates text by word count."""
@@ -64,14 +67,14 @@ def analyze_article(text: str) -> dict:
64
  """
65
 
66
  messages = [{"role": "user", "content": prompt}]
67
- response = client.chat.completions.create(
68
- model="llama-3.3-70b-versatile",
69
- messages=messages,
70
- max_tokens=300,
71
- temperature=0.1,
72
- response_format={"type": "json_object"}
73
  )
74
- llm_data = json.loads(response.choices[0].message.content)
75
 
76
  subjectivity_score = TextBlob(safe_text).sentiment.subjectivity
77
  raw_reading_ease = textstat.flesch_reading_ease(safe_text)
@@ -215,23 +218,22 @@ def check_contradiction(text_a: str, text_b: str) -> dict:
215
  Text 2: "{safe_b}"
216
  """
217
  messages = [{"role": "user", "content": prompt}]
218
- response = client.chat.completions.create(
219
- model="llama-3.3-70b-versatile",
220
- messages=messages,
221
- max_tokens=100,
222
- temperature=0.1,
223
- response_format={"type": "json_object"}
224
  )
225
-
226
- result = json.loads(response.choices[0].message.content)
227
  return {"relationship": result.get("relationship", "NEUTRAL"), "confidence": result.get("confidence", 0.0)}
228
 
229
 
230
  # USER INTERFACE
231
  st.set_page_config(page_title="FrameVis | Media Framing", layout="wide")
232
 
233
- if not GROQ_API_KEY:
234
- st.warning("Groq API Token Missing.")
235
  st.stop()
236
 
237
  st.markdown("""
 
5
  import streamlit as st
6
  from textblob import TextBlob
7
  import json
8
+ import google.generativeai as genai
9
  import os
10
  import concurrent.futures
 
11
  import textstat
12
  import trafilatura
13
  import requests
 
23
  URL_B = "https://edition.cnn.com/2026/03/30/world/live-news/iran-war-us-israel-trump"
24
 
25
  # Initialize the Hugging Face Client
26
+ GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
27
+ if GEMINI_API_KEY:
28
+ genai.configure(api_key=GEMINI_API_KEY)
29
+
30
+ ai_model = genai.GenerativeModel('gemini-1.5-pro')
31
 
32
  def _truncate_to_words(text: str, limit: int) -> str:
33
  """Truncates text by word count."""
 
67
  """
68
 
69
  messages = [{"role": "user", "content": prompt}]
70
+ response = ai_model.generate_content(
71
+ prompt,
72
+ generation_config=genai.GenerationConfig(
73
+ response_mime_type="application/json",
74
+ temperature=0.1,
75
+ )
76
  )
77
+ llm_data = json.loads(response.text)
78
 
79
  subjectivity_score = TextBlob(safe_text).sentiment.subjectivity
80
  raw_reading_ease = textstat.flesch_reading_ease(safe_text)
 
218
  Text 2: "{safe_b}"
219
  """
220
  messages = [{"role": "user", "content": prompt}]
221
+ response = ai_model.generate_content(
222
+ prompt,
223
+ generation_config=genai.GenerationConfig(
224
+ response_mime_type="application/json",
225
+ temperature=0.1,
226
+ )
227
  )
228
+ result = json.loads(response.text)
 
229
  return {"relationship": result.get("relationship", "NEUTRAL"), "confidence": result.get("confidence", 0.0)}
230
 
231
 
232
  # USER INTERFACE
233
  st.set_page_config(page_title="FrameVis | Media Framing", layout="wide")
234
 
235
+ if not GEMINI_API_KEY:
236
+ st.warning("Gemini API Token Missing.")
237
  st.stop()
238
 
239
  st.markdown("""