import gradio as gr import requests import huggingface_hub # Initialize the client, pointing it to one of the available models client = huggingface_hub.InferenceClient(model="mistralai/Mixtral-8x7B-Instruct-v0.1") PROMPT = """ Write a short, imperative description of the provided app's purpose. It MUST ALWAYS be under 80 characters and a single-sentence. You can mention some technology names that you extract from the source code. Example descriptions: "Remove background from images.", "Generate captions for images using ViT and GPT2.", "Predict the nutritional value of food based on an image of the food." The provided app.py file: """ def generate(spaces): output = "" space_ids = [ str.removeprefix("https://huggingface.co/spaces/") for str in spaces.split() if len(str) > 0 ] print(space_ids) for space_id in space_ids: # TODO(support non-app.py Spaces) app_py = requests.get( url=f"https://huggingface.co/spaces/{space_id}/resolve/main/app.py" ).text input = PROMPT + f"```py{app_py}```" chat_completion = client.chat_completion( messages=[ {"role": "user", "content": input}, ], max_tokens=500, ) output += chat_completion.choices[0].message.content + "\n" yield output iface = gr.Interface( description=""" ## Generate description for a space using a LLM Uses mixtral, feel free to duplicate to tweak stuff. """, fn=generate, inputs=gr.Textbox( label="list of Spaces to generate a description for", value=""" https://huggingface.co/spaces/julien-c/coqui https://huggingface.co/spaces/TTS-AGI/TTS-Arena https://huggingface.co/spaces/playgroundai/playground-v2.5 https://huggingface.co/spaces/amirgame197/Remove-Video-Background https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard """.strip(), ), outputs=gr.Textbox(label="descriptions", lines=4), ) iface.launch()