Spaces:
Sleeping
Sleeping
Runtime capacity error Bug fixed by Amit Kamal
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
8 |
|
9 |
|
|
|
|
|
10 |
# def respond(
|
11 |
# message,
|
12 |
# history: list[tuple[str, str]],
|
@@ -34,44 +36,76 @@ client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
|
34 |
# temperature=temperature,
|
35 |
# top_p=top_p,
|
36 |
# ):
|
37 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
# response += token
|
40 |
-
# yield response
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def respond(
|
44 |
-
message,
|
45 |
-
history: list[tuple[str, str]],
|
46 |
-
system_message,
|
47 |
-
max_tokens,
|
48 |
-
temperature,
|
49 |
-
top_p,
|
50 |
):
|
51 |
messages = [{"role": "system", "content": system_message}]
|
52 |
-
|
53 |
-
|
54 |
-
if val[0]:
|
55 |
-
messages.append({"role": "user", "content": val[0]})
|
56 |
-
if val[1]:
|
57 |
-
messages.append({"role": "assistant", "content": val[1]})
|
58 |
-
|
59 |
messages.append({"role": "user", "content": message})
|
60 |
|
61 |
response = ""
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
"""
|
77 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
@@ -92,6 +126,5 @@ demo = gr.ChatInterface(
|
|
92 |
],
|
93 |
)
|
94 |
|
95 |
-
|
96 |
if __name__ == "__main__":
|
97 |
-
demo.launch()
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# """
|
5 |
+
# For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
+
# """
|
7 |
+
# client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
8 |
|
9 |
|
10 |
+
|
11 |
+
# ##None type
|
12 |
# def respond(
|
13 |
# message,
|
14 |
# history: list[tuple[str, str]],
|
|
|
36 |
# temperature=temperature,
|
37 |
# top_p=top_p,
|
38 |
# ):
|
39 |
+
# if message.choices[0].delta.content is not None:
|
40 |
+
# token = message.choices[0].delta.content
|
41 |
+
# response += token
|
42 |
+
|
43 |
+
# yield response
|
44 |
+
|
45 |
+
# """
|
46 |
+
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
47 |
+
# """
|
48 |
+
# demo = gr.ChatInterface(
|
49 |
+
# respond,
|
50 |
+
# additional_inputs=[
|
51 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
52 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
53 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
54 |
+
# gr.Slider(
|
55 |
+
# minimum=0.1,
|
56 |
+
# maximum=1.0,
|
57 |
+
# value=0.95,
|
58 |
+
# step=0.05,
|
59 |
+
# label="Top-p (nucleus sampling)",
|
60 |
+
# ),
|
61 |
+
# ],
|
62 |
+
# )
|
63 |
+
|
64 |
+
|
65 |
+
# if __name__ == "__main__":
|
66 |
+
# demo.launch()
|
67 |
+
|
68 |
|
|
|
|
|
69 |
|
70 |
+
import gradio as gr
|
71 |
+
from huggingface_hub import InferenceClient
|
72 |
+
|
73 |
+
"""
|
74 |
+
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
75 |
+
"""
|
76 |
+
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
77 |
+
|
78 |
+
## None type
|
79 |
def respond(
|
80 |
+
message: str,
|
81 |
+
history: list[tuple[str, str]], # This will not be used
|
82 |
+
system_message: str,
|
83 |
+
max_tokens: int,
|
84 |
+
temperature: float,
|
85 |
+
top_p: float,
|
86 |
):
|
87 |
messages = [{"role": "system", "content": system_message}]
|
88 |
+
|
89 |
+
# Append only the latest user message
|
|
|
|
|
|
|
|
|
|
|
90 |
messages.append({"role": "user", "content": message})
|
91 |
|
92 |
response = ""
|
93 |
|
94 |
+
try:
|
95 |
+
# Generate response from the model
|
96 |
+
for message in client.chat_completion(
|
97 |
+
messages,
|
98 |
+
max_tokens=max_tokens,
|
99 |
+
stream=True,
|
100 |
+
temperature=temperature,
|
101 |
+
top_p=top_p,
|
102 |
+
):
|
103 |
+
if message.choices[0].delta.content is not None:
|
104 |
+
token = message.choices[0].delta.content
|
105 |
+
response += token
|
106 |
+
yield response
|
107 |
+
except Exception as e:
|
108 |
+
yield f"An error occurred: {e}"
|
109 |
|
110 |
"""
|
111 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
126 |
],
|
127 |
)
|
128 |
|
|
|
129 |
if __name__ == "__main__":
|
130 |
+
demo.launch()
|