asd
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
-
import os
|
2 |
import json
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
from peft import PeftModel
|
6 |
-
from huggingface_hub import HfApi
|
7 |
import gradio as gr
|
8 |
import time
|
9 |
|
@@ -11,22 +10,6 @@ import time
|
|
11 |
merged_model = None
|
12 |
tokenizer = None
|
13 |
|
14 |
-
def load_model_and_tokenizer():
|
15 |
-
global merged_model, tokenizer
|
16 |
-
|
17 |
-
model_name = "NoaiGPT/merged-llama3-8b-instruct"
|
18 |
-
local_model_path = model_name.replace("/", "_")
|
19 |
-
|
20 |
-
if os.path.exists(local_model_path):
|
21 |
-
print("Loading model from local path...")
|
22 |
-
tokenizer = AutoTokenizer.from_pretrained(local_model_path)
|
23 |
-
merged_model = AutoModelForCausalLM.from_pretrained(local_model_path)
|
24 |
-
else:
|
25 |
-
print("Downloading model from Hugging Face Hub...")
|
26 |
-
token = os.getenv("HF_AUTH_TOKEN") # Ensure you set this environment variable with your Hugging Face token
|
27 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=token)
|
28 |
-
merged_model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=token)
|
29 |
-
|
30 |
def merge_models():
|
31 |
print("Loading base model...")
|
32 |
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
|
@@ -57,12 +40,10 @@ def push_to_hub(repo_name):
|
|
57 |
except Exception as e:
|
58 |
print(f"Repository already exists or error occurred: {e}")
|
59 |
|
60 |
-
token = os.getenv("HF_AUTH_TOKEN") # Ensure you set this environment variable with your Hugging Face token
|
61 |
api.upload_folder(
|
62 |
folder_path="merged_model",
|
63 |
repo_id=repo_name,
|
64 |
repo_type="model",
|
65 |
-
token=token
|
66 |
)
|
67 |
print("Model pushed successfully!")
|
68 |
|
@@ -88,48 +69,22 @@ def run_merge_and_push():
|
|
88 |
|
89 |
# Generate a unique repository name
|
90 |
timestamp = int(time.time())
|
91 |
-
hub_repo_name = f"
|
92 |
|
93 |
# Push to Hugging Face Hub
|
94 |
push_to_hub(hub_repo_name)
|
95 |
|
96 |
return f"Model merged and pushed to Hugging Face Hub successfully! Repository: {hub_repo_name}"
|
97 |
|
98 |
-
# Load the model and tokenizer
|
99 |
-
load_model_and_tokenizer()
|
100 |
-
|
101 |
-
# Default input text
|
102 |
-
default_input_text = """### Human: Humanize the following AI-generated text. Ensure the output maintains the same format, headings, and bullet points as the input:
|
103 |
-
Monitor the implementation, adjusting the plan as needed.. Furthermore, introducing healthier snacks such as fresh fruits, vegetables, and alternative grains can help counteract the effects of processed and sugary snacks that are popular amongst students.
|
104 |
-
3. Introduce nutritious whole foods such as fresh fruits and vegetables, grains, seeds, and nuts, as well as plant-based substitutes to traditional lunch items.
|
105 |
-
5. Set aside time for students to participate in activities that promote healthy eating habits.
|
106 |
-
|
107 |
-
To effectively implement healthier food options in school cafeterias, the following steps should be taken:
|
108 |
-
|
109 |
-
1.
|
110 |
-
6.
|
111 |
-
4. Studies have found that students who eat healthier, balanced meals during the school day perform better in class, have higher cognitive functioning, and feel more energized and ready to learn. Survey the students to learn their preferences for healthy snacks. Establish a partnership with local farmers and food vendors to provide fresh, wholesome food items for the school lunchroom. Conduct an audit of the current food items offered in the school lunchroom. Educate the students on the importance of making healthier food choices.
|
112 |
-
7.
|
113 |
-
2.
|
114 |
-
Research has shown that there are numerous benefits to providing healthier food options in school cafeterias
|
115 |
-
### Assistant:Its better to take away the opition of getting junk food that the cafeteria puts out for students. Changing our school meun to much healthier choice's is a good idea because its good for the students to eat much healthier food in school. Some students tend to buy food and then throw it out becuase of how the food is made. And staff members that get lunch from the cafeteria could enjoy having a healthier lunch.
|
116 |
-
|
117 |
-
in conclusion changing the schools cafeterias meun to much healthier choice would be good for students and staff members so they could stay healthy and focus.. Eating junk food could make you tired and you won't have theenergy to do anything. The school could make a slald bar for those who chose to eat it and they could add there own toppings so they could eat somthing they like instead of throwing it out.
|
118 |
-
|
119 |
-
I think having fruits smoothies, organic bake goods, and a salad bar could be very good for every school to have because the school could make a lot of money selling this at school and its healthy for students to eat and enjoy. Students wont be so tempted to eat it, and could chose a better and healthier choice.
|
120 |
-
|
121 |
-
Most students want to stay in shape, so they try to eat healthier. most students don't workout so they depend on the food they eat. most students wont have to get uber eats to get food that they like if the school sold smoothies or bake goods. adding more healthier choices in th school caferteria meun could help them stay in shape. Eating more fresh fruits and water can help students focus and not fall asleep in class"""
|
122 |
-
|
123 |
# Gradio interface
|
124 |
with gr.Blocks() as demo:
|
125 |
with gr.Tab("Generate Text"):
|
126 |
iface = gr.Interface(
|
127 |
fn=generate_text,
|
128 |
-
inputs=gr.Textbox(lines=
|
129 |
-
outputs=gr.Textbox(lines=
|
130 |
title="Merged Llama 3 8B Instruct Model",
|
131 |
description="Enter text to generate a response from the merged model.",
|
132 |
-
examples=[[default_input_text]]
|
133 |
)
|
134 |
iface.render()
|
135 |
|
|
|
|
|
1 |
import json
|
2 |
import torch
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
from peft import PeftModel
|
5 |
+
from huggingface_hub import HfApi
|
6 |
import gradio as gr
|
7 |
import time
|
8 |
|
|
|
10 |
merged_model = None
|
11 |
tokenizer = None
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def merge_models():
|
14 |
print("Loading base model...")
|
15 |
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
|
|
|
40 |
except Exception as e:
|
41 |
print(f"Repository already exists or error occurred: {e}")
|
42 |
|
|
|
43 |
api.upload_folder(
|
44 |
folder_path="merged_model",
|
45 |
repo_id=repo_name,
|
46 |
repo_type="model",
|
|
|
47 |
)
|
48 |
print("Model pushed successfully!")
|
49 |
|
|
|
69 |
|
70 |
# Generate a unique repository name
|
71 |
timestamp = int(time.time())
|
72 |
+
hub_repo_name = f"your-username/merged-llama3-8b-instruct-{timestamp}"
|
73 |
|
74 |
# Push to Hugging Face Hub
|
75 |
push_to_hub(hub_repo_name)
|
76 |
|
77 |
return f"Model merged and pushed to Hugging Face Hub successfully! Repository: {hub_repo_name}"
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Gradio interface
|
80 |
with gr.Blocks() as demo:
|
81 |
with gr.Tab("Generate Text"):
|
82 |
iface = gr.Interface(
|
83 |
fn=generate_text,
|
84 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
85 |
+
outputs=gr.Textbox(lines=10, label="Generated Text"),
|
86 |
title="Merged Llama 3 8B Instruct Model",
|
87 |
description="Enter text to generate a response from the merged model.",
|
|
|
88 |
)
|
89 |
iface.render()
|
90 |
|