diff --git a/html/index.html b/html/index.html
new file mode 100644
index 0000000..4cc2fe5
--- /dev/null
+++ b/html/index.html
@@ -0,0 +1,73 @@
+
+
+
+
+
+ 习题识别工具
+
+
+
+
+
+
导航页面
+
请选择您要前往的页面
+
+
+ 上传页面
+ 接收终端
+
+
+
+
+
+
+
+
+
diff --git a/html/terminal.html b/html/terminal.html
new file mode 100644
index 0000000..ba410f2
--- /dev/null
+++ b/html/terminal.html
@@ -0,0 +1,153 @@
+
+
+
+
+
+ 接收终端
+
+
+
+
+
+
终端-习题识别工具
+
这里将接收来自上传端的习题图像及其识别结果
+
+
![Received Image]()
+
+
+
+
+
+
+
+
+ 复制
+ 清空
+
+
+
+
+
+
+
+
+
diff --git a/html/upload.html b/html/upload.html
new file mode 100644
index 0000000..4f9068f
--- /dev/null
+++ b/html/upload.html
@@ -0,0 +1,186 @@
+
+
+
+
+
+ 习题上传
+
+
+
+
+
+
上传-习题识别工具
+
请上传习题图片,AI将自动处理并返回结果。
+
+
+
+
+
请直接粘贴图片
+
或将图像拖放到此处
+
+
![Uploaded Image]()
+
+
点击上传或替换当前图片
+
+
+
+
+
+
+ 发送
+ 清空
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main.py b/main.py
index 7367f54..7ce5f68 100644
--- a/main.py
+++ b/main.py
@@ -1,27 +1,16 @@
-from fastapi import FastAPI, WebSocket, WebSocketDisconnect, HTTPException, UploadFile, File
+from fastapi import FastAPI, WebSocket, WebSocketDisconnect, UploadFile, File
from fastapi.responses import StreamingResponse, HTMLResponse
-from pydantic import BaseModel
from typing import List
import base64
-import asyncio
import openai
app = FastAPI()
-with open("key", "r") as f:
- key = f.read()
+with open("key", "r") as k:
+ key = k.read()
client = openai.OpenAI(api_key=key,
- base_url="https://open.bigmodel.cn/api/paas/v4/"
- )
-
-
-@app.get("/")
-async def root():
- return {"message": "Hello World"}
-
-
-@app.get("/hello/{name}")
-async def say_hello(name: str):
- return {"message": f"Hello {name}"}
+ base_url="https://open.bigmodel.cn/api/paas/v4/")
+with open("prompt", "r", encoding="utf-8") as p:
+ prompt = p.read()
# WebSocket连接管理器
@@ -36,7 +25,8 @@ class ConnectionManager:
def disconnect(self, websocket: WebSocket):
self.active_connections.remove(websocket)
- async def send_personal_message(self, message: str, websocket: WebSocket):
+ @staticmethod
+ async def send_personal_message(message: str, websocket: WebSocket):
await websocket.send_text(message)
async def broadcast(self, message: str):
@@ -52,9 +42,10 @@ manager = ConnectionManager()
# WebSocket端点
-@app.websocket("/event")
+@app.websocket("/listener")
async def event(websocket: WebSocket):
await manager.connect(websocket)
+ print("Client connected")
try:
while True:
# 这里可以添加逻辑处理来自客户端的消息
@@ -80,7 +71,7 @@ async def predict(file: UploadFile = File(...)):
"content": [
{
"type": "text",
- "text": "请描述该图片",
+ "text": prompt,
},
{
"type": "image_url",
@@ -109,7 +100,19 @@ async def predict(file: UploadFile = File(...)):
return StreamingResponse(stream_response(), media_type="text/plain")
-@app.get("/test", response_class=HTMLResponse)
+@app.get("/terminal", response_class=HTMLResponse)
async def test():
- with open("test.html", "r", encoding="utf-8") as f:
+ with open("html/terminal.html", "r", encoding="utf-8") as f:
+ return f.read()
+
+
+@app.get("/upload", response_class=HTMLResponse)
+async def test():
+ with open("html/upload.html", "r", encoding="utf-8") as f:
+ return f.read()
+
+
+@app.get("/", response_class=HTMLResponse)
+async def test():
+ with open("html/index.html", "r", encoding="utf-8") as f:
return f.read()
diff --git a/prompt b/prompt
new file mode 100644
index 0000000..42ae953
--- /dev/null
+++ b/prompt
@@ -0,0 +1 @@
+请直接输出图片中的习题内容。不要输出除了题目内容外的各种提示语,比如“好的,下面我将...”。不要输出已经图中的题目里已经填写的答案,只要题干。请将按照方便粘贴到word文档的格式进行输出,避免使用markdown格式。遇到题干里有无法转为文字的部分,比如题目的选项为图片等情况,预留好空位并放置一个标记[图片]即可。
\ No newline at end of file
diff --git a/test.html b/test.html
deleted file mode 100644
index 933786d..0000000
--- a/test.html
+++ /dev/null
@@ -1,132 +0,0 @@
-
-
-
-
-
- WebSocket 文本和图片接收器
-
-
-
-
-
-
-
![Received Image]()
-
-
-
-
-
-
-
-
- 复制
- 清空
-
-
-
-
-
-
-
-
-