Spaces:
Sleeping
Sleeping
jonathanjordan21
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
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("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
|
10 |
def respond(
|
@@ -14,16 +15,30 @@ def respond(
|
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
|
|
|
|
17 |
):
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
|
|
23 |
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
|
|
25 |
|
26 |
-
messages.append({"role": "user", "content": message})
|
|
|
27 |
|
28 |
response = ""
|
29 |
|
@@ -55,6 +70,8 @@ demo = gr.ChatInterface(
|
|
55 |
step=0.05,
|
56 |
label="Top-p (nucleus sampling)",
|
57 |
),
|
|
|
|
|
58 |
],
|
59 |
)
|
60 |
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from langchain_community.chat_models import ChatOllama
|
4 |
+
from langchain_core.prompts import ChatPromptTemplate
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
+
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
|
11 |
def respond(
|
|
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
+
model_name="llama3-8b",
|
19 |
+
api_key=None
|
20 |
):
|
21 |
+
client = ChatOllama(
|
22 |
+
model=model_name,
|
23 |
+
base_url="https://lintasmediadanawa-hf-llm-api.hf.space",
|
24 |
+
headers={"Authorization": f"Bearer {api_key}"},
|
25 |
+
temperature=temperature,
|
26 |
+
top_p=top_p,
|
27 |
+
max_tokens=max_tokens
|
28 |
+
)
|
29 |
+
|
30 |
+
messages = [("system", system_message)]
|
31 |
|
32 |
for val in history:
|
33 |
if val[0]:
|
34 |
+
# messages.append({"role": "user", "content": val[0]})
|
35 |
+
messages.append(("human", val[0]))
|
36 |
if val[1]:
|
37 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
38 |
+
messages.append(("ai", val[1]))
|
39 |
|
40 |
+
# messages.append({"role": "user", "content": message})
|
41 |
+
messages.append(("user", message))
|
42 |
|
43 |
response = ""
|
44 |
|
|
|
70 |
step=0.05,
|
71 |
label="Top-p (nucleus sampling)",
|
72 |
),
|
73 |
+
gr.Textbox(value="llama3-8b", label="Available Model Name, please refer to https://lintasmediadanawa-hf-llm-api.hf.space/api/tags")
|
74 |
+
gr.Textbox(value="hf_xxx", label="Huggingface API key")
|
75 |
],
|
76 |
)
|
77 |
|