gradio: Node client not working on nestjs project
Describe the bug
I tried the gradio node client on new and existings nestjs project and all give me this error:
Error: No "exports" main defined in projects/nest-gradio/node_modules/@gradio/client/package.json
at new NodeError (node:internal/errors:387:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
at packageExportsResolve (node:internal/modules/esm/resolve:589:7)
at resolveExports (node:internal/modules/cjs/loader:554:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1012:27)
at Function.Module._load (node:internal/modules/cjs/loader:871:27)
at Module.require (node:internal/modules/cjs/loader:1098:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (projects/nest-gradio/src/app.controller.ts:3:1)
and this is my minimal app.controller.ts:
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { client } from '@gradio/client';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
async getHello() {
const app = await client('xlm-roberta-base');
const info =app.view_api();
return info;
}
}
Is there an existing issue for this?
- I have searched the existing issues
Reproduction
- Create a brand new nestjs project.
$ npm i -g @nestjs/cli
$ nest new project-name
- Install gradio node client
npm i @gradio/client
- Edit the app.controller.ts to add some gradio client test:
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { client } from '@gradio/client';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
async test() {
const app = await client('xlm-roberta-base');
const info =app.view_api();
return info;
}
}
Run the app:
npm run start
The console (at least for me) then shows the mentioned error.
Screenshot
No response
Logs
Debugger listening on ws://127.0.0.1:42371/430d33b9-4fe3-4df9-8101-76e339641d68
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Error: No "exports" main defined in /home/me/projects/nest-gradio/node_modules/@gradio/client/package.json
at new NodeError (node:internal/errors:387:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
at packageExportsResolve (node:internal/modules/esm/resolve:589:7)
at resolveExports (node:internal/modules/cjs/loader:554:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1012:27)
at Function.Module._load (node:internal/modules/cjs/loader:871:27)
at Module.require (node:internal/modules/cjs/loader:1098:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (/home/me/projects/nest-gradio/src/app.controller.ts:3:1)
Waiting for the debugger to disconnect...
^CWaiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
System Info
Gradio node client "version": "0.1.1"
OS: Ubuntu 22.04.2 LTS
[System Information]
OS Version : Linux 5.19
NodeJS Version : v18.16.0
NPM Version : 9.5.1
[Nest CLI]
Nest CLI Version : 9.5.0
[Nest Platform Information]
platform-express version : 9.4.1
schematics version : 9.2.0
testing version : 9.4.1
common version : 9.4.1
core version : 9.4.1
cli version : 9.5.0
Severity
blocking all usage of gradio
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 13
- Comments: 16 (4 by maintainers)
you may try this work-around for importing @gradio/client in commonjs module (e.g. nestjs app) this works for me:
Thanks @lisandropuzzolo for opening the issue. cc-ing @pngwn
@galipmedia the reason we created the client is because using Gradio apps as an API can be pretty involved, so there isn’t a simple way to do it.
I’ll follow up the other comments in this thread shortly.
I have a big legacy project that uses commonjs, it would be a nightmare to switch every file to import syntax. I cannot find any way to incorporate gradio/client. Is it possible to hit the huggingface endpoints with just axios and a bearer token ? I have tried a bit but cannot even seem to be able to find the correct endpoint url. Tried https://huggingface.co/api/spaces/${space_id} /host /predict but both say cannot be POSTed to.