unclemusclez commited on
Commit
b681a48
Β·
verified Β·
1 Parent(s): 8038b3d

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +83 -0
App.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
3
+ import requests
4
+
5
+
6
+ processed_inputs = {}
7
+ def process_inputs(model_id, q_method, email, oauth_token: gr.OAuthToken | None, profile: gr.OAuthProfile | None):
8
+ if oauth_token is None or profile is None or oauth_token.token is None or profile.username is None:
9
+ return "### You must be logged in to use this service."
10
+
11
+ if not model_id or not q_method or not email:
12
+ return "### All fields are required!"
13
+
14
+ input_hash = hash((model_id, q_method, oauth_token.token, profile.username))
15
+
16
+ if input_hash in processed_inputs and processed_inputs[input_hash] == 200:
17
+ return "### Oops! 😲 Looks like you've already submitted this task πŸš€. Please hang tight! We'll send you an email with all the details once it's ready πŸ’Œ. Thanks for your patience! 😊"
18
+
19
+ url = "https://sdk.nexa4ai.com/task"
20
+
21
+ data = {
22
+ "repository_url": f"https://huggingface.co/{model_id}",
23
+ "username": profile.username,
24
+ "access_token": oauth_token.token,
25
+ "email": email,
26
+ "quantization_option": q_method,
27
+ }
28
+ """
29
+ # OAuth Token Information:
30
+ # - This is an OAuth token, not a user's password.
31
+ # - We need the OAuth token to clone the related repository and access its contents.
32
+ # - As mentioned in the README.md, only read permission is requested, which includes:
33
+ # - Read access to your public profile
34
+ # - Read access to the content of all your public repos
35
+ # - The token expires after 60 minutes.
36
+ # - For more information about OAuth, please refer to the official documentation:
37
+ # https://huggingface.co/docs/hub/en/spaces-oauth
38
+ """
39
+ response = requests.post(url, json=data)
40
+
41
+ if response.status_code == 200:
42
+ processed_inputs[input_hash] = 200
43
+ return "### Your request has been submitted successfully! 🌟 We'll notify you by email πŸ“§ once everything is processed. 😊"
44
+ else:
45
+ processed_inputs[input_hash] = response.status_code
46
+ return f"### Failed to submit request: {response.text}"
47
+
48
+ iface = gr.Interface(
49
+ fn=process_inputs,
50
+ inputs=[
51
+ HuggingfaceHubSearch(
52
+ label="Hub Model ID",
53
+ placeholder="Search for model id on Huggingface",
54
+ search_type="model",
55
+ ),
56
+ gr.Dropdown(
57
+ ["q2_K", "q3_K", "q3_K_S", "q3_K_M", "q3_K_L", "q4_0", "q4_1", "q4_K", "q4_K_S", "q4_K_M", "q5_0", "q5_1", "q5_K", "q5_K_S", "q5_K_M", "q6_K", "q8_0", "f16"],
58
+ label="Quantization Option",
59
+ info="GGML quantisation options",
60
+ value="q4_0",
61
+ filterable=False
62
+ ),
63
+ gr.Textbox(label="Email", placeholder="Enter your email here")
64
+ ],
65
+ outputs = gr.Markdown(
66
+ label="output",
67
+ value="### Please enter the model URL, select a quantization method, and provide your email address."
68
+ ),
69
+ allow_flagging="never"
70
+ )
71
+
72
+ theme = gr.themes.Soft(text_size="lg", spacing_size="lg")
73
+ with gr.Blocks(theme=theme) as demo:
74
+ with gr.Row(variant="panel'"):
75
+ gr.Markdown(value="## πŸš€ Unleash the Power of Custom GGML Quantized Models! ⚑"),
76
+ gr.LoginButton(min_width=380)
77
+
78
+ gr.Markdown(value="🚨 **IMPORTANT:** You **MUST** grant access to the model repository before use.")
79
+ gr.Markdown(value="πŸ”” You **MUST** be logged in to use this service.")
80
+ iface.render()
81
+ gr.Markdown(value="We sincerely thank our community members, [Perry](https://huggingface.co/PerryCheng614), [Brian](https://huggingface.co/JoyboyBrian), [Qi](https://huggingface.co/qiqiWav), [David](https://huggingface.co/Davidqian123), for their extraordinary contributions to this GGUF converter project.")
82
+
83
+ demo.launch(share=True)