PG1204 commented on code in PR #5124: URL: https://github.com/apache/texera/pull/5124#discussion_r3326822539
########## amber/src/main/scala/org/apache/texera/web/resource/HuggingFaceModelResource.scala: ########## @@ -0,0 +1,672 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.web.resource + +import com.fasterxml.jackson.core.`type`.TypeReference +import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper} +import com.google.common.cache.{Cache, CacheBuilder} +import kong.unirest.Unirest +import org.slf4j.{Logger, LoggerFactory} + +import java.io.InputStream +import java.net.URI +import java.nio.file.{Files, Path => NioPath, Paths} +import java.util.concurrent.{Callable, ForkJoinPool, TimeUnit} +import java.util.stream.Collectors +import javax.ws.rs._ +import javax.ws.rs.core.{MediaType, Response} +import scala.jdk.CollectionConverters._ + +/** + * REST resource that proxies the Hugging Face Hub API for the HuggingFace operator. + * + * - GET /api/huggingface/models?task=…[&search=…] browse or search HF models + * - GET /api/huggingface/tasks list HF pipeline tags with hosted inference + * - POST /api/huggingface/upload-audio?filename=… stream-upload an audio file + * - GET /api/huggingface/audio-preview?path=… stream back an uploaded audio file + * - GET /api/huggingface/media-proxy?url=… proxy an allowlisted remote media URL + * + * Token sourcing: the user supplies their own HF token via the `X-HF-Token` + * request header (forwarded by the frontend from the operator's property + * panel). If the header is absent, requests go to HF Hub anonymously — + * HF serves public model/task lists at public rate limits without auth. + * The browse cache is bypassed whenever a user token is supplied, so one + * user's private-model visibility never leaks into another user's response. + */ +@Path("/huggingface") +@Produces(Array(MediaType.APPLICATION_JSON)) +class HuggingFaceModelResource { Review Comment: @xuang7 The annotation has been added. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
