Skip to content

Commit

Permalink
fix: auto size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Nov 19, 2024
1 parent b3ab680 commit cd693a9
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
- Prompt supports Chinese and English (Chinese will automatically call `AI` translation)
- `API` provided by `CloudflareAI` and `HuggingFace`

## TODO

- [ ] Implement `Image-to-text` feature
- [ ] Add preview images to `README.md`
| ![](./readme/2.png) | ![](./readme/1.png) | ![](./readme/3.png) |
| :---: | :---: | :---: |

## Usage

Expand Down
2 changes: 1 addition & 1 deletion app/api/prompt/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function POST(req: Request): Promise<Response> {
const url = `https://api.cloudflare.com/client/v4/accounts/${process.env.CF_USER_ID}/ai/run/@cf/unum/uform-gen2-qwen-500m`
const body = {
image: image as number[],
max_tokens: 2048,
max_tokens: 4096,
prompt: 'Generate a detailed description in a single paragraph for this image',
}
const response = await fetch(url, {
Expand Down
5 changes: 3 additions & 2 deletions app/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ export default function Prompt() {
showUploadList={false}
accept='.jpg,.jpeg,.png'
beforeUpload={async (file) => {
const MAX_SIZE_MB = 2
try {
flushSync(() => setDisabled(true))
if (file.size > 2 * 1024 * 1024) {
alert('Image size should be less than 2MB')
if (file.size > MAX_SIZE_MB * 1024 * 1024) {
alert(`Image size should be less than ${MAX_SIZE_MB}MB`)
return false
}
const uint8array = new Uint8Array(await file.arrayBuffer())
Expand Down
5 changes: 2 additions & 3 deletions app/lib/useImageSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export function useImageSize(containerID: string): number {
return Math.min(container?.clientWidth || 0, container?.clientHeight || 0) - 48
}
const subSize = (callback: () => void) => {
const container = document.getElementById(containerID)
container?.addEventListener('resize', callback)
return () => container?.removeEventListener('resize', callback)
window.addEventListener('resize', callback)
return () => window.removeEventListener('resize', callback)
}
return useSyncExternalStore(subSize, getSize, () => 0)
}
Binary file added readme/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cd693a9

Please sign in to comment.