File size: 2,122 Bytes
e8825a9
5e94338
 
e8825a9
5e94338
9b19366
e8825a9
5e94338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b1fdf0
 
 
5e94338
 
 
9b19366
5e94338
 
 
 
 
11b11bf
5e94338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8825a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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('"') + "\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()