Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial fork #960

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ frontend/node_modules
.azure/
__pycache__/
.ipynb_checkpoints/
/venv
25 changes: 25 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
render_template,
)

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient
from openai import AsyncAzureOpenAI
from azure.identity.aio import (
DefaultAzureCredential,
Expand Down Expand Up @@ -834,6 +836,29 @@ async def ensure_cosmos():
else:
return jsonify({"error": "CosmosDB is not working"}), 500

@bp.route("/indexupload", methods=["GET", "POST"])
async def upload_to_index():
for name, file in (await request.files).items():
print(f'Processing {name}: {len(file.read())}')
credential = AzureKeyCredential("254a5a937d6a4975bf7ed705d75c6a42")
document_analysis_client = DocumentAnalysisClient("https://sbd-ea-useast2-sbx-formrecognizer.cognitiveservices.azure.com/", credential)

# The local file path to the document you want to analyze
document_path = r""
# Submitting the document for analysis
analyze_result = document_analysis_client.begin_analyze_document("prebuilt-layout", document=file).result()

# Convert the analysis result to JSON
result_json = analyze_result.to_dict()
with open("temp/analyze_result.json", "w") as f:
json.dump(result_json, f, indent=4)

# Save the JSON to a local file
output_json_path = r""
with open(output_json_path, "w") as output_file:
json.dump(result_json, output_file, indent=4)
print("Analysis result saved to:", output_json_path)


async def generate_title(conversation_messages):
## make sure the messages are sorted by _ts descending
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export async function conversationApi(options: ConversationRequest, abortSignal:
return response
}

export async function uploadFileToIndex(event: any): Promise<null> {
const fd = new FormData()
console.log(event)
const file = event.target.files[0]
console.log(file)
fd.append("file", file)
let response = fetch('/indexupload', {
method: 'POST',
body: fd,
//headers: {
// 'Content-Type': 'multipart/form-data',
//},
})
return null
}

export async function getUserInfo(): Promise<UserInfo[]> {
const response = await fetch('/.auth/me')
if (!response.ok) {
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
CosmosDBStatus,
ErrorMessage,
ExecResults,
AzureSqlServerCodeExecResult
AzureSqlServerCodeExecResult,
uploadFileToIndex
} from "../../api";
import { Answer } from "../../components/Answer";
import { QuestionInput } from "../../components/QuestionInput";
Expand Down Expand Up @@ -732,7 +733,8 @@ const Chat = () => {
appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading
)
}

const fileUpload = useRef<HTMLInputElement>(null)

return (
<div className={styles.container} role="main">
{showAuthMessage ? (
Expand Down Expand Up @@ -841,6 +843,10 @@ const Chat = () => {
</Stack>
)}
<Stack>
<div className="sidebar-header" onClick={() => {fileUpload.current?.click()}} role="button">
<button>Upload File</button>
<input ref={fileUpload} type="file" onChange={uploadFileToIndex} hidden={true}/>
</div>
{appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && (
<CommandBarButton
role="button"
Expand Down
106 changes: 53 additions & 53 deletions static/assets/index-274bb812.js → static/assets/index-457cc918.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/x-icon" href="{{ favicon }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ title }}</title>
<script type="module" crossorigin src="/assets/index-274bb812.js"></script>
<script type="module" crossorigin src="/assets/index-457cc918.js"></script>
<link rel="stylesheet" href="/assets/index-61492790.css">
</head>
<body>
Expand Down