julien-c's picture
julien-c HF staff
Sometimes it adds a space before " (#6)
794048c verified
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:
app_file = huggingface_hub.SpaceCard.load(space_id).data.get("app_file", "app.py")
with open(huggingface_hub.hf_hub_download(space_id, repo_type="space", filename=app_file)) as app_file_path:
app_py = app_file_path.read()
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.strip().strip('"') + "\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.queue(default_concurrency_limit=20).launch()