pvanand commited on
Commit
005f2d7
1 Parent(s): 6343686

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -1
main.py CHANGED
@@ -2,7 +2,7 @@ from fastapi import FastAPI, HTTPException, Request, Query
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from pydantic import BaseModel
4
  from typing import List, Dict, Any
5
- from helper_functions_api import md_to_html, search_brave, fetch_and_extract_content, limit_tokens, together_response, insert_data
6
  import os
7
  from dotenv import load_dotenv, find_dotenv
8
  from datetime import datetime, timedelta
@@ -119,7 +119,25 @@ async def generate_report(query: QueryModel):
119
  system_prompt_final = prompt_system["offline"]
120
 
121
  md_report = together_response(user_prompt_final, model=llm_default_medium, SysPrompt=system_prompt_final)
 
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  if user_id != "test":
124
  insert_data(user_id, query_str, description, str(all_text_with_urls), md_report)
125
  references_html = {}
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from pydantic import BaseModel
4
  from typing import List, Dict, Any
5
+ from helper_functions_api import has_tables, extract_data_from_tag, openrouter_response,md_to_html, search_brave, fetch_and_extract_content, limit_tokens, together_response, insert_data
6
  import os
7
  from dotenv import load_dotenv, find_dotenv
8
  from datetime import datetime, timedelta
 
119
  system_prompt_final = prompt_system["offline"]
120
 
121
  md_report = together_response(user_prompt_final, model=llm_default_medium, SysPrompt=system_prompt_final)
122
+ html_report = md_to_html(md_report)
123
 
124
+ # Render Charts
125
+ if has_tables(html_report):
126
+ print("tables found, creating charts")
127
+ try:
128
+
129
+ prompt = "convert the numerical data tables in the given content to embedded html plotly.js charts if appropriate, use appropriate colors, \
130
+ output format:\
131
+ <report>output the full content without any other changes in md format enclosed in tags like this</report> using the following:" + str(md_report)
132
+
133
+ messages = [{"role": 'user', "content": prompt}]
134
+ md_report_chart = extract_data_from_tag(openrouter_response(messages, model="anthropic/claude-3.5-sonnet"),"report")
135
+ html_report = md_to_html(md_report_chart)
136
+
137
+ except Exception as e:
138
+ print(e)
139
+ print("failed to generate charts, falling back to original report")
140
+
141
  if user_id != "test":
142
  insert_data(user_id, query_str, description, str(all_text_with_urls), md_report)
143
  references_html = {}