Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Initialize the text generation pipeline with the specified model
|
5 |
pipe = pipeline("text-generation", model="chargoddard/Yi-34B-Llama", device=0)
|
6 |
|
|
|
|
|
|
|
|
|
7 |
def respond(
|
8 |
message,
|
9 |
history: list[tuple[str, str]],
|
@@ -12,6 +30,15 @@ def respond(
|
|
12 |
temperature,
|
13 |
top_p,
|
14 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
messages = [{"role": "system", "content": system_message}]
|
16 |
|
17 |
for val in history:
|
@@ -53,5 +80,5 @@ demo = gr.ChatInterface(
|
|
53 |
],
|
54 |
)
|
55 |
|
56 |
-
|
57 |
-
|
|
|
1 |
+
# Install necessary libraries
|
2 |
+
!pip install torch torchvision -f https://download.pytorch.org/whl/cu80/torch_stable.html
|
3 |
+
!pip install gradio transformers
|
4 |
+
!pip install tensorflow
|
5 |
+
|
6 |
+
# Import required libraries
|
7 |
import gradio as gr
|
8 |
from transformers import pipeline
|
9 |
+
import torch
|
10 |
+
import threading
|
11 |
+
import time
|
12 |
+
import tensorflow as tf
|
13 |
+
|
14 |
+
# Check GPU availability
|
15 |
+
print(torch.cuda.is_available())
|
16 |
+
print(tf.test.gpu_device_name())
|
17 |
|
18 |
# Initialize the text generation pipeline with the specified model
|
19 |
pipe = pipeline("text-generation", model="chargoddard/Yi-34B-Llama", device=0)
|
20 |
|
21 |
+
# Rate limiting parameters
|
22 |
+
rate_limit = 5 # Number of requests per second
|
23 |
+
last_request_time = 0
|
24 |
+
|
25 |
def respond(
|
26 |
message,
|
27 |
history: list[tuple[str, str]],
|
|
|
30 |
temperature,
|
31 |
top_p,
|
32 |
):
|
33 |
+
global last_request_time
|
34 |
+
|
35 |
+
# Apply rate limiting
|
36 |
+
elapsed_time = time.time() - last_request_time
|
37 |
+
if elapsed_time < 1.0 / rate_limit:
|
38 |
+
time.sleep(1.0 / rate_limit - elapsed_time)
|
39 |
+
|
40 |
+
last_request_time = time.time()
|
41 |
+
|
42 |
messages = [{"role": "system", "content": system_message}]
|
43 |
|
44 |
for val in history:
|
|
|
80 |
],
|
81 |
)
|
82 |
|
83 |
+
# Launch the Gradio interface
|
84 |
+
demo.launch()
|