rairo commited on
Commit
a3645a5
·
verified ·
1 Parent(s): 03e6a39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -14,6 +14,8 @@ from langchain.vectorstores import FAISS
14
  from langchain.text_splitter import CharacterTextSplitter
15
  from langchain.chains import ConversationalRetrievalChain
16
  from langchain.memory import ConversationBufferMemory
 
 
17
 
18
  # Import Supadata and initialize the client
19
  from supadata import Supadata, SupadataError
@@ -87,6 +89,7 @@ def get_data(search_term):
87
  st.error(f"An error occurred for search term: {search_term}, error: {e}. Please try again.")
88
  return {}
89
 
 
90
  def get_data_from_url(url):
91
  """
92
  Scrape the provided URL using Supadata and pass the page content directly to the Gemini model
@@ -97,7 +100,6 @@ def get_data_from_url(url):
97
  page_content = web_content.content
98
  full_prompt = (
99
  "Extract the following grant data from the provided web content. "
100
- "List me all grants or funds with:\n"
101
  "- Grant name/title\n"
102
  "- Short summary\n"
103
  "- Funding organization\n"
@@ -109,12 +111,12 @@ def get_data_from_url(url):
109
  "Return in JSON format.\n\n"
110
  f"Web content: {page_content}"
111
  )
112
- llm = ChatGoogleGenerativeAI(
113
- model="gemini-2.0-flash-thinking-exp", google_api_key=GOOGLE_API_KEY, temperature=0
114
- )
115
- response = llm.invoke(full_prompt)
116
  try:
117
- result = json.loads(response.content)
 
118
  except Exception as parse_error:
119
  st.error("Error parsing JSON from Gemini model response.")
120
  return {}
 
14
  from langchain.text_splitter import CharacterTextSplitter
15
  from langchain.chains import ConversationalRetrievalChain
16
  from langchain.memory import ConversationBufferMemory
17
+ from google import genai
18
+ from google.genai import types
19
 
20
  # Import Supadata and initialize the client
21
  from supadata import Supadata, SupadataError
 
89
  st.error(f"An error occurred for search term: {search_term}, error: {e}. Please try again.")
90
  return {}
91
 
92
+
93
  def get_data_from_url(url):
94
  """
95
  Scrape the provided URL using Supadata and pass the page content directly to the Gemini model
 
100
  page_content = web_content.content
101
  full_prompt = (
102
  "Extract the following grant data from the provided web content. "
 
103
  "- Grant name/title\n"
104
  "- Short summary\n"
105
  "- Funding organization\n"
 
111
  "Return in JSON format.\n\n"
112
  f"Web content: {page_content}"
113
  )
114
+ client = genai.Client(api_key=GOOGLE_API_KEY)
115
+ new_answer = client.models.generate_content(model="models/gemini-2.0-flash-lite", contents=f"{full_prompt}, return the json string and nothing else")
116
+ response = new_answer.text
 
117
  try:
118
+ result = json.loads(response)
119
+ st.success(f"{result[0]}")
120
  except Exception as parse_error:
121
  st.error("Error parsing JSON from Gemini model response.")
122
  return {}