implemented in dev mode 🤯
Browse files- README.md +2 -2
- app.py +64 -3
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Description Generator
|
3 |
-
emoji:
|
4 |
colorFrom: gray
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.0
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: Description Generator
|
3 |
+
emoji: 🔥
|
4 |
colorFrom: gray
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.0
|
8 |
app_file: app.py
|
app.py
CHANGED
@@ -1,7 +1,68 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import requests
|
4 |
+
import huggingface_hub
|
5 |
|
6 |
+
# Initialize the client, pointing it to one of the available models
|
7 |
+
client = OpenAI(
|
8 |
+
base_url="https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1/v1/",
|
9 |
+
api_key=huggingface_hub.get_token(),
|
10 |
+
)
|
11 |
|
12 |
+
|
13 |
+
PROMPT = """
|
14 |
+
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.
|
15 |
+
|
16 |
+
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."
|
17 |
+
|
18 |
+
The provided app.py file:
|
19 |
+
"""
|
20 |
+
|
21 |
+
|
22 |
+
def generate(spaces):
|
23 |
+
output = ""
|
24 |
+
space_ids = [
|
25 |
+
str.removeprefix("https://huggingface.co/spaces/")
|
26 |
+
for str in spaces.split()
|
27 |
+
if len(str) > 0
|
28 |
+
]
|
29 |
+
print(space_ids)
|
30 |
+
for space_id in space_ids:
|
31 |
+
# TODO(support non-app.py Spaces)
|
32 |
+
app_py = requests.get(
|
33 |
+
url=f"https://huggingface.co/spaces/{space_id}/resolve/main/app.py"
|
34 |
+
).text
|
35 |
+
|
36 |
+
input = PROMPT + f"```py{app_py}```"
|
37 |
+
|
38 |
+
chat_completion = client.chat.completions.create(
|
39 |
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
40 |
+
messages=[
|
41 |
+
{"role": "user", "content": input},
|
42 |
+
],
|
43 |
+
max_tokens=500,
|
44 |
+
)
|
45 |
+
output += chat_completion.choices[0].message.content + "\n"
|
46 |
+
yield output
|
47 |
+
|
48 |
+
|
49 |
+
iface = gr.Interface(
|
50 |
+
description="""
|
51 |
+
## Generate description for a space using a LLM
|
52 |
+
|
53 |
+
Uses mixtral, feel free to duplicate to tweak stuff.
|
54 |
+
""",
|
55 |
+
fn=generate,
|
56 |
+
inputs=gr.Textbox(
|
57 |
+
label="list of Spaces to generate a description for",
|
58 |
+
value="""
|
59 |
+
https://huggingface.co/spaces/julien-c/coqui
|
60 |
+
https://huggingface.co/spaces/TTS-AGI/TTS-Arena
|
61 |
+
https://huggingface.co/spaces/playgroundai/playground-v2.5
|
62 |
+
https://huggingface.co/spaces/amirgame197/Remove-Video-Background
|
63 |
+
https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard
|
64 |
+
""".strip(),
|
65 |
+
),
|
66 |
+
outputs=gr.Textbox(label="descriptions", lines=4),
|
67 |
+
)
|
68 |
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
openai
|