Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
def respond(
|
| 6 |
message,
|
| 7 |
history: list[dict[str, str]],
|
|
@@ -14,19 +16,28 @@ def respond(
|
|
| 14 |
"""
|
| 15 |
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
|
| 16 |
"""
|
| 17 |
-
client =
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
messages.extend(history)
|
| 22 |
-
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
-
|
| 25 |
response = ""
|
| 26 |
-
|
| 27 |
for message in client.chat_completion(
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
stream=True,
|
| 31 |
temperature=temperature,
|
| 32 |
top_p=top_p,
|
|
@@ -35,11 +46,11 @@ def respond(
|
|
| 35 |
token = ""
|
| 36 |
if len(choices) and choices[0].delta.content:
|
| 37 |
token = choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
"""
|
|
@@ -59,12 +70,12 @@ chatbot = gr.ChatInterface(
|
|
| 59 |
),
|
| 60 |
],
|
| 61 |
)
|
| 62 |
-
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
with gr.Sidebar():
|
| 65 |
gr.LoginButton()
|
| 66 |
chatbot.render()
|
| 67 |
-
|
| 68 |
-
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
#from transformers import pipeline
|
| 4 |
+
from huggingface_hub.inference._providers import PROVIDER_OR_POLICY_T
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
def respond(
|
| 8 |
message,
|
| 9 |
history: list[dict[str, str]],
|
|
|
|
| 16 |
"""
|
| 17 |
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
|
| 18 |
"""
|
| 19 |
+
#client = pipeline("text-generation", model="nosadaniel/llama3-1-8b-tuned")
|
| 20 |
+
#client = InferenceClient(token=hf_token.token, model="nosadaniel/llama3-1-8b-tuned")
|
| 21 |
+
|
| 22 |
+
model="meta-llama/Meta-Llama-3.1-8B-Instruct-LoRa:phishing-email-adJu"
|
| 23 |
+
base_url="https://api.tokenfactory.nebius.com/v1/"
|
| 24 |
+
api_key="v1.CmQKHHN0YXRpY2tleS1lMDBkMXh2ZDdheDAwNXhxMGgSIXNlcnZpY2VhY2NvdW50LWUwMGp0eHNrM3pubjdyYXQ0azIMCPHv7MgGEJ_k6PEBOgwI8PKElAcQwO2YywNAAloDZTAw.AAAAAAAAAAH-boLssQhDYJht_li9Ql7MN1rSmj_8DXmYlZ13NhdavV0NYylvY_HkVQrALXt2z9Pm5_aQn-tt--Mbc1W8G78E"
|
| 25 |
+
|
| 26 |
+
client = InferenceClient( base_url=base_url, api_key=api_key, provider=PROVIDER_OR_POLICY_T)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
messages = [{"role": "system", "content": system_message}]
|
| 30 |
+
|
| 31 |
messages.extend(history)
|
| 32 |
+
|
| 33 |
messages.append({"role": "user", "content": message})
|
| 34 |
+
|
| 35 |
response = ""
|
| 36 |
+
|
| 37 |
for message in client.chat_completion(
|
| 38 |
+
model = model,
|
| 39 |
+
messages = messages,
|
| 40 |
+
max_tokens=max_tokens,
|
| 41 |
stream=True,
|
| 42 |
temperature=temperature,
|
| 43 |
top_p=top_p,
|
|
|
|
| 46 |
token = ""
|
| 47 |
if len(choices) and choices[0].delta.content:
|
| 48 |
token = choices[0].delta.content
|
| 49 |
+
|
| 50 |
response += token
|
| 51 |
yield response
|
| 52 |
+
|
| 53 |
+
|
| 54 |
"""
|
| 55 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 56 |
"""
|
|
|
|
| 70 |
),
|
| 71 |
],
|
| 72 |
)
|
| 73 |
+
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
with gr.Sidebar():
|
| 76 |
gr.LoginButton()
|
| 77 |
chatbot.render()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
if __name__ == "__main__":
|
| 81 |
demo.launch()
|