Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import json
|
3 |
import logging
|
4 |
from datetime import datetime
|
@@ -11,7 +10,6 @@ logging.basicConfig(level=logging.INFO)
|
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
13 |
# System prompts remain the same as before
|
14 |
-
# System prompts
|
15 |
CONVERSATION_PROMPT = """You are LOSS DOG, a professional profile builder. Your goal is to have natural conversations
|
16 |
with users to gather information about their professional background across 9 categories:
|
17 |
|
@@ -29,7 +27,8 @@ Be friendly and conversational. Ask follow-up questions naturally. When appropri
|
|
29 |
but respect their boundaries. Once you believe you have gathered sufficient information (or if the user indicates they
|
30 |
have nothing more to share), let them know they can click 'Generate Profile' to proceed.
|
31 |
"""
|
32 |
-
|
|
|
33 |
|
34 |
ANALYTICAL PROCESS:
|
35 |
1. Read entire conversation history
|
@@ -208,7 +207,9 @@ Remember to:
|
|
208 |
- Cross-reference information for consistency
|
209 |
- Make reasonable inferences when appropriate
|
210 |
- Maintain consistent formatting
|
211 |
-
- Include all required fields even if empty
|
|
|
|
|
212 |
class ProfileBuilder:
|
213 |
def __init__(self):
|
214 |
self.conversation_history = []
|
@@ -270,12 +271,21 @@ class ProfileBuilder:
|
|
270 |
temperature=0.3
|
271 |
)
|
272 |
|
273 |
-
#
|
274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
-
#
|
277 |
profile = {
|
278 |
"profile_data": profile_data,
|
|
|
279 |
"metadata": {
|
280 |
"generated_at": datetime.now().isoformat(),
|
281 |
"conversation_length": len(self.conversation_history)
|
@@ -323,7 +333,10 @@ def create_gradio_interface():
|
|
323 |
|
324 |
with gr.Column(scale=1):
|
325 |
generate_btn = gr.Button("Generate Profile")
|
326 |
-
|
|
|
|
|
|
|
327 |
download_btn = gr.File(label="Download Profile")
|
328 |
|
329 |
# Event handlers
|
@@ -342,8 +355,12 @@ def create_gradio_interface():
|
|
342 |
async def on_generate():
|
343 |
result = await builder.generate_profile()
|
344 |
if "error" in result:
|
345 |
-
|
346 |
-
|
|
|
|
|
|
|
|
|
347 |
|
348 |
# Bind events
|
349 |
msg.submit(
|
@@ -360,7 +377,7 @@ def create_gradio_interface():
|
|
360 |
|
361 |
generate_btn.click(
|
362 |
on_generate,
|
363 |
-
outputs=[profile_output, download_btn]
|
364 |
)
|
365 |
|
366 |
return demo
|
@@ -371,4 +388,4 @@ if __name__ == "__main__":
|
|
371 |
demo.launch(
|
372 |
server_name="0.0.0.0",
|
373 |
server_port=7860
|
374 |
-
)
|
|
|
|
|
1 |
import json
|
2 |
import logging
|
3 |
from datetime import datetime
|
|
|
10 |
logger = logging.getLogger(__name__)
|
11 |
|
12 |
# System prompts remain the same as before
|
|
|
13 |
CONVERSATION_PROMPT = """You are LOSS DOG, a professional profile builder. Your goal is to have natural conversations
|
14 |
with users to gather information about their professional background across 9 categories:
|
15 |
|
|
|
27 |
but respect their boundaries. Once you believe you have gathered sufficient information (or if the user indicates they
|
28 |
have nothing more to share), let them know they can click 'Generate Profile' to proceed.
|
29 |
"""
|
30 |
+
|
31 |
+
EXTRACTION_PROMPT = """You are a professional information extraction system. Your task is to methodically analyze conversations and organize information into 9 specific categories. Process each category thoroughly and output in structured JSON format with no additional text.
|
32 |
|
33 |
ANALYTICAL PROCESS:
|
34 |
1. Read entire conversation history
|
|
|
207 |
- Cross-reference information for consistency
|
208 |
- Make reasonable inferences when appropriate
|
209 |
- Maintain consistent formatting
|
210 |
+
- Include all required fields even if empty
|
211 |
+
"""
|
212 |
+
|
213 |
class ProfileBuilder:
|
214 |
def __init__(self):
|
215 |
self.conversation_history = []
|
|
|
271 |
temperature=0.3
|
272 |
)
|
273 |
|
274 |
+
# Get the raw output text from the model
|
275 |
+
raw_output = completion.choices[0].message.content
|
276 |
+
logger.info(f"Raw extraction output: {raw_output}")
|
277 |
+
|
278 |
+
# Attempt to parse the JSON
|
279 |
+
try:
|
280 |
+
profile_data = json.loads(raw_output)
|
281 |
+
except json.JSONDecodeError as decode_error:
|
282 |
+
logger.error("Failed to decode JSON. The output may not be valid JSON.")
|
283 |
+
profile_data = None # Indicate failure to parse
|
284 |
|
285 |
+
# Build the profile output including metadata and raw output
|
286 |
profile = {
|
287 |
"profile_data": profile_data,
|
288 |
+
"raw_output": raw_output,
|
289 |
"metadata": {
|
290 |
"generated_at": datetime.now().isoformat(),
|
291 |
"conversation_length": len(self.conversation_history)
|
|
|
333 |
|
334 |
with gr.Column(scale=1):
|
335 |
generate_btn = gr.Button("Generate Profile")
|
336 |
+
# JSON output for structured profile
|
337 |
+
profile_output = gr.JSON(label="Generated Profile (Parsed JSON)")
|
338 |
+
# Markdown output to always show the raw AI output
|
339 |
+
raw_output_markdown = gr.Markdown(label="Raw Output from AI")
|
340 |
download_btn = gr.File(label="Download Profile")
|
341 |
|
342 |
# Event handlers
|
|
|
355 |
async def on_generate():
|
356 |
result = await builder.generate_profile()
|
357 |
if "error" in result:
|
358 |
+
error_text = f"Error generating profile: {result['error']}"
|
359 |
+
return {"error": error_text}, None, error_text
|
360 |
+
profile = result["profile"]
|
361 |
+
# Prepare the raw output as markdown. Wrapping in triple backticks for code formatting.
|
362 |
+
raw_markdown = f"```json\n{profile.get('raw_output', '')}\n```"
|
363 |
+
return profile, result["filename"], raw_markdown
|
364 |
|
365 |
# Bind events
|
366 |
msg.submit(
|
|
|
377 |
|
378 |
generate_btn.click(
|
379 |
on_generate,
|
380 |
+
outputs=[profile_output, download_btn, raw_output_markdown]
|
381 |
)
|
382 |
|
383 |
return demo
|
|
|
388 |
demo.launch(
|
389 |
server_name="0.0.0.0",
|
390 |
server_port=7860
|
391 |
+
)
|