Spaces:
Sleeping
Sleeping
Commit
·
7fb6a75
1
Parent(s):
18fbc58
app.py
CHANGED
@@ -1,55 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
from typing import List, Tuple, Dict
|
4 |
|
|
|
|
|
|
|
5 |
client = InferenceClient("AuriLab/gpt-bi-instruct-cesar")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
top_p = 0.85
|
23 |
-
|
24 |
-
messages = format_messages(history, system_message, message)
|
25 |
response = ""
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
except Exception as e:
|
45 |
-
yield f"Error: {str(e)}"
|
46 |
-
|
47 |
-
# Update the ChatInterface to use async function
|
48 |
demo = gr.ChatInterface(
|
49 |
-
|
50 |
-
title="
|
51 |
-
examples=["nola duzu izena?", "Nola egiten duzu?"]
|
52 |
)
|
53 |
|
|
|
54 |
if __name__ == "__main__":
|
55 |
-
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("AuriLab/gpt-bi-instruct-cesar")
|
8 |
|
9 |
+
|
10 |
+
def respond(
|
11 |
+
message,
|
12 |
+
history: list[tuple[str, str]],
|
13 |
+
):
|
14 |
+
messages = [{"role": "system", "content": "Gpt-Bi zara, AuriLabsek sortutako assitente digitala."}]
|
15 |
+
|
16 |
+
for val in history:
|
17 |
+
if val[0]:
|
18 |
+
messages.append({"role": "user", "content": val[0]})
|
19 |
+
if val[1]:
|
20 |
+
messages.append({"role": "assistant", "content": val[1]})
|
21 |
+
|
22 |
+
messages.append({"role": "user", "content": message})
|
23 |
+
|
|
|
|
|
|
|
24 |
response = ""
|
25 |
+
|
26 |
+
for message in client.chat_completion(
|
27 |
+
messages,
|
28 |
+
max_tokens=200,
|
29 |
+
stream=True,
|
30 |
+
temperature=0.7,
|
31 |
+
top_p=50,
|
32 |
+
):
|
33 |
+
token = message.choices[0].delta.content
|
34 |
+
|
35 |
+
response += token
|
36 |
+
yield response
|
37 |
+
|
38 |
+
|
39 |
+
"""
|
40 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
41 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
42 |
demo = gr.ChatInterface(
|
43 |
+
respond,
|
44 |
+
title="GPT-BI Instruct",
|
|
|
45 |
)
|
46 |
|
47 |
+
|
48 |
if __name__ == "__main__":
|
49 |
+
demo.launch()
|