Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,3 +4,30 @@ gr.load("models/Qwen/Qwen2.5-72B").launch()
|
|
4 |
model = gr.load("model_path") # Load the model only once at startup
|
5 |
def predict(input_data):
|
6 |
return model(input_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
model = gr.load("model_path") # Load the model only once at startup
|
5 |
def predict(input_data):
|
6 |
return model(input_data)
|
7 |
+
|
8 |
+
# Inference pipeline
|
9 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
10 |
+
|
11 |
+
# Chat function
|
12 |
+
def chat_with_model(prompt, max_tokens=100):
|
13 |
+
responses = generator(prompt, max_length=max_tokens, do_sample=True, temperature=0.7, top_k=50)
|
14 |
+
return responses[0]["generated_text"]
|
15 |
+
|
16 |
+
# Gradio Interface
|
17 |
+
with gr.Blocks() as chat_interface:
|
18 |
+
gr.Markdown("# 🚀 Super Fast ChatGPT")
|
19 |
+
with gr.Row():
|
20 |
+
with gr.Column():
|
21 |
+
user_input = gr.Textbox(label="Enter your message", placeholder="Type something...")
|
22 |
+
max_tokens = gr.Slider(50, 300, value=100, step=10, label="Max Tokens")
|
23 |
+
send_button = gr.Button("Send")
|
24 |
+
with gr.Column():
|
25 |
+
chat_output = gr.Textbox(label="ChatGPT's Response", placeholder="Response will appear here...", interactive=False)
|
26 |
+
|
27 |
+
send_button.click(fn=chat_with_model, inputs=[user_input, max_tokens], outputs=chat_output)
|
28 |
+
from transformers import BitsAndBytesConfig
|
29 |
+
quant_config = BitsAndBytesConfig(load_in_4bit=True)
|
30 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, quantization_config=quant_config)
|
31 |
+
|
32 |
+
# Launch the app
|
33 |
+
chat_interface.launch(share=False, server_name="0.0.0.0", server_port=7860)
|