Spaces:
Running
Running
mopdernised code
Browse files- app.py +13 -9
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
@@ -5,7 +6,10 @@ from huggingface_hub import InferenceClient
|
|
| 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 |
-
client = InferenceClient(
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def respond(
|
|
@@ -33,20 +37,20 @@ def respond(
|
|
| 33 |
|
| 34 |
response = ""
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
messages,
|
| 38 |
max_tokens=max_tokens,
|
| 39 |
-
stream=True,
|
| 40 |
temperature=temperature,
|
| 41 |
top_p=top_p,
|
|
|
|
| 42 |
):
|
| 43 |
-
if
|
| 44 |
-
|
| 45 |
-
if
|
| 46 |
-
response +=
|
| 47 |
yield response
|
| 48 |
-
|
| 49 |
-
yield "Please clear the history and try again."
|
| 50 |
|
| 51 |
"""
|
| 52 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
|
|
|
| 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 |
+
client = InferenceClient(
|
| 10 |
+
"meta-llama/Meta-Llama-3-8B-Instruct",
|
| 11 |
+
token=os.environ.get("HF_TOKEN")
|
| 12 |
+
)
|
| 13 |
|
| 14 |
|
| 15 |
def respond(
|
|
|
|
| 37 |
|
| 38 |
response = ""
|
| 39 |
|
| 40 |
+
# Stream the model output safely
|
| 41 |
+
for msg in client.chat_completion(
|
| 42 |
messages,
|
| 43 |
max_tokens=max_tokens,
|
|
|
|
| 44 |
temperature=temperature,
|
| 45 |
top_p=top_p,
|
| 46 |
+
stream=True,
|
| 47 |
):
|
| 48 |
+
if hasattr(msg, "choices") and msg.choices:
|
| 49 |
+
delta = msg.choices[0].delta
|
| 50 |
+
if hasattr(delta, "content") and delta.content:
|
| 51 |
+
response += delta.content
|
| 52 |
yield response
|
| 53 |
+
# Ignore any events that do not contain content
|
|
|
|
| 54 |
|
| 55 |
"""
|
| 56 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
huggingface_hub>=0.23.0
|