dygoo commited on
Commit
39fcc34
Β·
verified Β·
1 Parent(s): 1a9c6ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -11,12 +11,15 @@ anthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
11
 
12
  # === 1. Simplified Search Workflow ===
13
 
14
- def search_workflow(name: str, progress=gr.Progress()):
15
  """
16
  A simple function to search for articles, fetching exactly 8 news articles: 4 recent, 4 historical.
17
  """
18
  if not name or not name.strip():
19
  return "❌ Please enter a company name.", ""
 
 
 
20
 
21
  progress(0, desc="Starting search...")
22
 
@@ -77,12 +80,15 @@ def search_workflow(name: str, progress=gr.Progress()):
77
 
78
  # === 2. Simplified Extraction Workflow ===
79
 
80
- def extraction_workflow(raw_text: str, company_name: str, progress=gr.Progress()):
81
  """
82
  A simple and robust tool to extract founders from text using the AI model.
83
  """
84
  if not raw_text or not raw_text.strip():
85
  return "❌ Please run a search first to get text to analyze."
 
 
 
86
 
87
  progress(0, desc="Preparing prompt for AI...")
88
 
@@ -98,7 +104,11 @@ ARTICLES:
98
  """
99
  try:
100
  progress(0.5, desc="Sending request to AI model...")
101
- message = anthropic_client.messages.create(
 
 
 
 
102
  model="claude-sonnet-4-20250514", # As requested
103
  max_tokens=1024,
104
  temperature=0.0,
@@ -135,30 +145,40 @@ ARTICLES:
135
 
136
  with gr.Blocks(title="Founder Name Extraction Tool", theme=gr.themes.Soft()) as demo:
137
  gr.Markdown("# πŸ”Ž Founder Name Extraction")
138
- gr.Markdown("A tool to find company founders. **Step 1:** Search for articles. **Step 2:** Extract founders' names from the results.")
139
 
140
  # Hidden state to pass text from search to extraction
141
  search_results_for_ai = gr.State("")
142
 
143
  with gr.Row():
144
- name_input = gr.Textbox(label="Company Name", placeholder="e.g., 'OpenAI', 'SpaceX'", scale=3)
145
- search_btn = gr.Button("1. πŸ” Search for Articles", variant="primary", scale=1)
 
 
 
 
 
 
 
 
 
 
146
 
147
  with gr.Row():
148
- extract_btn = gr.Button("2. πŸ“Š Extract Founders from Search Results", variant="secondary")
149
 
150
  # Display both sections without tabs
151
  gr.Markdown("### Search Results")
152
  output_search = gr.Markdown()
153
 
154
  gr.Markdown("### Founder Intelligence Report")
155
- output_extract = gr.Markdown(value="*Waiting for extraction...*") # Shows placeholder text
156
 
157
  # --- Event Wiring ---
158
  # Search button populates the search results and the hidden state
159
  search_btn.click(
160
  fn=search_workflow,
161
- inputs=[name_input],
162
  outputs=[output_search, search_results_for_ai],
163
  show_progress="full"
164
  )
@@ -166,7 +186,7 @@ with gr.Blocks(title="Founder Name Extraction Tool", theme=gr.themes.Soft()) as
166
  # Extract button uses the hidden state to populate the extraction
167
  extract_btn.click(
168
  fn=extraction_workflow,
169
- inputs=[search_results_for_ai, name_input],
170
  outputs=[output_extract],
171
  show_progress="full"
172
  )
 
11
 
12
  # === 1. Simplified Search Workflow ===
13
 
14
+ def search_workflow(name: str, api_key: str, progress=gr.Progress()):
15
  """
16
  A simple function to search for articles, fetching exactly 8 news articles: 4 recent, 4 historical.
17
  """
18
  if not name or not name.strip():
19
  return "❌ Please enter a company name.", ""
20
+
21
+ if not api_key or not api_key.strip():
22
+ return "❌ Please enter your Anthropic API key.", ""
23
 
24
  progress(0, desc="Starting search...")
25
 
 
80
 
81
  # === 2. Simplified Extraction Workflow ===
82
 
83
+ def extraction_workflow(raw_text: str, company_name: str, api_key: str, progress=gr.Progress()):
84
  """
85
  A simple and robust tool to extract founders from text using the AI model.
86
  """
87
  if not raw_text or not raw_text.strip():
88
  return "❌ Please run a search first to get text to analyze."
89
+
90
+ if not api_key or not api_key.strip():
91
+ return "❌ Please enter your Anthropic API key."
92
 
93
  progress(0, desc="Preparing prompt for AI...")
94
 
 
104
  """
105
  try:
106
  progress(0.5, desc="Sending request to AI model...")
107
+
108
+ # Create client with user's API key
109
+ client = anthropic.Anthropic(api_key=api_key)
110
+
111
+ message = client.messages.create(
112
  model="claude-sonnet-4-20250514", # As requested
113
  max_tokens=1024,
114
  temperature=0.0,
 
145
 
146
  with gr.Blocks(title="Founder Name Extraction Tool", theme=gr.themes.Soft()) as demo:
147
  gr.Markdown("# πŸ”Ž Founder Name Extraction")
148
+ gr.Markdown("A tool to find company founders. **Step 1:** Enter your API key and company name. **Step 2:** Search for articles. **Step 3:** Extract founders' names from the results.")
149
 
150
  # Hidden state to pass text from search to extraction
151
  search_results_for_ai = gr.State("")
152
 
153
  with gr.Row():
154
+ api_key_input = gr.Textbox(
155
+ label="Anthropic API Key",
156
+ placeholder="sk-ant-...",
157
+ type="password",
158
+ scale=2
159
+ )
160
+ name_input = gr.Textbox(
161
+ label="Company Name",
162
+ placeholder="e.g., 'OpenAI', 'SpaceX'",
163
+ scale=2
164
+ )
165
+ search_btn = gr.Button("2. πŸ” Search for Articles", variant="primary", scale=1)
166
 
167
  with gr.Row():
168
+ extract_btn = gr.Button("3. πŸ“Š Extract Founders from Search Results", variant="secondary")
169
 
170
  # Display both sections without tabs
171
  gr.Markdown("### Search Results")
172
  output_search = gr.Markdown()
173
 
174
  gr.Markdown("### Founder Intelligence Report")
175
+ output_extract = gr.Markdown(value="*Waiting for extraction...*")
176
 
177
  # --- Event Wiring ---
178
  # Search button populates the search results and the hidden state
179
  search_btn.click(
180
  fn=search_workflow,
181
+ inputs=[name_input, api_key_input], # Added api_key_input
182
  outputs=[output_search, search_results_for_ai],
183
  show_progress="full"
184
  )
 
186
  # Extract button uses the hidden state to populate the extraction
187
  extract_btn.click(
188
  fn=extraction_workflow,
189
+ inputs=[search_results_for_ai, name_input, api_key_input], # Added api_key_input
190
  outputs=[output_extract],
191
  show_progress="full"
192
  )