wu981526092 commited on
Commit
f0c156e
·
1 Parent(s): c27493d

Fix API baseUrl for HF Spaces - use current domain for all environments

Browse files
frontend/src/pages/Models.tsx CHANGED
@@ -41,7 +41,7 @@ export function Models() {
41
 
42
  const fetchModels = async () => {
43
  try {
44
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
45
  const res = await fetch(`${baseUrl}/models`)
46
  if (res.ok) {
47
  const data: ModelsResponse = await res.json()
@@ -57,7 +57,7 @@ export function Models() {
57
  const handleLoadModel = async (modelName: string) => {
58
  setModelLoading(modelName)
59
  try {
60
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
61
  const res = await fetch(`${baseUrl}/load-model`, {
62
  method: 'POST',
63
  headers: { 'Content-Type': 'application/json' },
@@ -76,7 +76,7 @@ export function Models() {
76
 
77
  const handleUnloadModel = async (modelName: string) => {
78
  try {
79
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
80
  const res = await fetch(`${baseUrl}/unload-model`, {
81
  method: 'POST',
82
  headers: { 'Content-Type': 'application/json' },
 
41
 
42
  const fetchModels = async () => {
43
  try {
44
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
45
  const res = await fetch(`${baseUrl}/models`)
46
  if (res.ok) {
47
  const data: ModelsResponse = await res.json()
 
57
  const handleLoadModel = async (modelName: string) => {
58
  setModelLoading(modelName)
59
  try {
60
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
61
  const res = await fetch(`${baseUrl}/load-model`, {
62
  method: 'POST',
63
  headers: { 'Content-Type': 'application/json' },
 
76
 
77
  const handleUnloadModel = async (modelName: string) => {
78
  try {
79
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
80
  const res = await fetch(`${baseUrl}/unload-model`, {
81
  method: 'POST',
82
  headers: { 'Content-Type': 'application/json' },
frontend/src/pages/Playground.tsx CHANGED
@@ -179,7 +179,7 @@ export function Playground() {
179
  const selectedModelInfo = models.find(m => m.model_name === selectedModel)
180
  if (!selectedModelInfo) return
181
 
182
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
183
 
184
  // If selected model is a local model and not loaded, show confirmation
185
  if (selectedModelInfo.type === 'local' && !selectedModelInfo.is_loaded) {
@@ -227,7 +227,7 @@ export function Playground() {
227
  setAutoLoadingModel(pendingModelToLoad.model_name)
228
 
229
  try {
230
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
231
  const response = await fetch(`${baseUrl}/load-model`, {
232
  method: 'POST',
233
  headers: { 'Content-Type': 'application/json' },
@@ -272,7 +272,7 @@ export function Playground() {
272
  // Cleanup: unload all local models when component unmounts or user leaves
273
  useEffect(() => {
274
  const handlePageUnload = async () => {
275
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
276
  const loadedLocalModels = models.filter(m => m.type === 'local' && m.is_loaded)
277
 
278
  for (const model of loadedLocalModels) {
@@ -297,7 +297,7 @@ export function Playground() {
297
 
298
  const fetchModels = async () => {
299
  try {
300
- const baseUrl = window.location.hostname === 'localhost' ? `${window.location.protocol}//${window.location.host}` : ''
301
  const res = await fetch(`${baseUrl}/models`)
302
  if (res.ok) {
303
  const data: ModelsResponse = await res.json()
 
179
  const selectedModelInfo = models.find(m => m.model_name === selectedModel)
180
  if (!selectedModelInfo) return
181
 
182
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
183
 
184
  // If selected model is a local model and not loaded, show confirmation
185
  if (selectedModelInfo.type === 'local' && !selectedModelInfo.is_loaded) {
 
227
  setAutoLoadingModel(pendingModelToLoad.model_name)
228
 
229
  try {
230
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
231
  const response = await fetch(`${baseUrl}/load-model`, {
232
  method: 'POST',
233
  headers: { 'Content-Type': 'application/json' },
 
272
  // Cleanup: unload all local models when component unmounts or user leaves
273
  useEffect(() => {
274
  const handlePageUnload = async () => {
275
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
276
  const loadedLocalModels = models.filter(m => m.type === 'local' && m.is_loaded)
277
 
278
  for (const model of loadedLocalModels) {
 
297
 
298
  const fetchModels = async () => {
299
  try {
300
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
301
  const res = await fetch(`${baseUrl}/models`)
302
  if (res.ok) {
303
  const data: ModelsResponse = await res.json()
static/assets/index-7718555c.js ADDED
The diff for this file is too large to render. See raw diff
 
static/assets/index-7718555c.js.map ADDED
The diff for this file is too large to render. See raw diff
 
static/index.html CHANGED
@@ -5,7 +5,7 @@
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>Edge LLM</title>
8
- <script type="module" crossorigin src="/assets/index-b709415f.js"></script>
9
  <link rel="stylesheet" href="/assets/index-7c5904a5.css">
10
  </head>
11
  <body>
 
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>Edge LLM</title>
8
+ <script type="module" crossorigin src="/assets/index-7718555c.js"></script>
9
  <link rel="stylesheet" href="/assets/index-7c5904a5.css">
10
  </head>
11
  <body>