acecalisto3 commited on
Commit
94dc208
·
verified ·
1 Parent(s): f136f10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -36
app.py CHANGED
@@ -1,38 +1,57 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- from components.database_page import database_page
5
- from components.documentation_page import documentation_page
6
- from components.home import home
7
- from components.lang_page import lang_page
8
- from components.optimization_page import optimization_page
9
- from components.refactor_page import refactor_page
10
- from components.style_page import style_page
11
- from components.test_page import test_page
12
-
13
- # Gradio interface
14
- def setup_interface():
15
- with gr.Blocks() as demo:
16
- gr.Markdown("### Select Model and Task")
17
- with gr.Row():
18
- model_name = gr.Dropdown(label="Model", choices=["gpt2", "bert-base-uncased"])
19
- task = gr.Dropdown(label="Task", choices=["text-generation", "text-classification"])
20
- input_data = gr.Textbox(label="Input")
21
- output = gr.Textbox(label="Output")
22
-
23
- input_data.change(fn=model_inference, inputs=[model_name, task, input_data], outputs=output)
24
-
25
- return demo
26
-
27
- # Function to generate text or perform other tasks based on model selection
28
- def model_inference(model_name, task, input_data):
29
- try:
30
- model_pipeline = pipeline(task, model=model_name)
31
- result = model_pipeline(input_data)
32
- return result
33
- except Exception as e:
34
- return f"Error: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
- interface = setup_interface()
38
- interface.launch()
 
1
+ from transformers import HfApi, pipeline
2
+
3
+ # Function to merge models at equal weights
4
+ def merge_models(models):
5
+ model_weights = [1.0 / len(models) for _ in range(len(models))]
6
+ merged_model = pipeline("text-generation", model=models, model_weights=model_weights)
7
+ return merged_model
8
+
9
+ # Retrieve code-generative models with config.json
10
+ def get_code_generative_models():
11
+ api = HfApi()
12
+ models_list = api.list_models()
13
+
14
+ code_generative_models = []
15
+
16
+ for model in models_list:
17
+ model_id = model.modelId
18
+ model_info = api.model_info(model_id)
19
+
20
+ if "config.json" in model_info.keys():
21
+ code_generative_models.append(model_id)
22
+
23
+ return code_generative_models
24
+
25
+ # Main function to merge models and deploy the merged model
26
+ def main():
27
+ code_generative_models = get_code_generative_models()
28
+
29
+ if len(code_generative_models) < 2:
30
+ print("At least two code-generative models with config.json files are required for merging.")
31
+ return
32
+
33
+ models = [model for model in code_generative_models[:2]] # Select the first two models for merging
34
+ merged_model = merge_models(models)
35
+
36
+ # Embed the merged model into a chat app for testing
37
+ chat_app = pipeline("text-generation", model=merged_model)
38
+
39
+ # Provide options for the user to download the code/config or deploy the merged model
40
+ print("Chat App Ready for Testing!")
41
+ print("Options:")
42
+ print("1. Download Code/Config")
43
+ print("2. Deploy as a Unique Space (Requires Write-Permission API Key)")
44
+
45
+ user_choice = input("Enter your choice (1 or 2): ")
46
+
47
+ if user_choice == "1":
48
+ # Download code/config
49
+ merged_model.save_pretrained("merged_model")
50
+
51
+ elif user_choice == "2":
52
+ # Deploy as a Unique Space with write-permission API Key
53
+ api_key = input("Enter your write-permission API Key: ")
54
+ # Code to deploy the merged model using the provided API key
55
 
56
  if __name__ == "__main__":
57
+ main()