Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("salmapm/llama2_salma")
|
| 8 |
-
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
@@ -27,21 +24,20 @@ def respond(
|
|
| 27 |
|
| 28 |
response = ""
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
""
|
| 43 |
-
|
| 44 |
-
"""
|
| 45 |
demo = gr.ChatInterface(
|
| 46 |
respond,
|
| 47 |
additional_inputs=[
|
|
@@ -58,6 +54,5 @@ demo = gr.ChatInterface(
|
|
| 58 |
],
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Initialisez le client sans token
|
| 5 |
+
client = InferenceClient(model="salmapm/llama2_salma")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def respond(
|
| 8 |
message,
|
|
|
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
|
| 27 |
+
try:
|
| 28 |
+
for message in client.chat_completion(
|
| 29 |
+
messages,
|
| 30 |
+
max_tokens=max_tokens,
|
| 31 |
+
stream=True,
|
| 32 |
+
temperature=temperature,
|
| 33 |
+
top_p=top_p,
|
| 34 |
+
):
|
| 35 |
+
token = message.choices[0].delta.content
|
| 36 |
+
response += token
|
| 37 |
+
yield response
|
| 38 |
+
except Exception as e:
|
| 39 |
+
yield f"An error occurred: {e}"
|
| 40 |
+
|
|
|
|
| 41 |
demo = gr.ChatInterface(
|
| 42 |
respond,
|
| 43 |
additional_inputs=[
|
|
|
|
| 54 |
],
|
| 55 |
)
|
| 56 |
|
|
|
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
demo.launch()
|