Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
|
| 10 |
def respond(
|
|
@@ -29,18 +27,20 @@ def respond(
|
|
| 29 |
|
| 30 |
messages.append({"role": "user", "content": template_instruction})
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
messages,
|
| 36 |
-
max_tokens=max_tokens,
|
| 37 |
-
stream=True,
|
| 38 |
-
temperature=temperature,
|
| 39 |
-
top_p=top_p,
|
| 40 |
-
):
|
| 41 |
-
token = message.choices[0].delta.content
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
yield response
|
| 45 |
|
| 46 |
"""
|
|
@@ -51,7 +51,7 @@ demo = gr.ChatInterface(
|
|
| 51 |
additional_inputs=[
|
| 52 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 53 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 54 |
-
gr.Slider(minimum=0.1, maximum
|
| 55 |
gr.Slider(
|
| 56 |
minimum=0.1,
|
| 57 |
maximum=1.0,
|
|
@@ -63,6 +63,5 @@ demo = gr.ChatInterface(
|
|
| 63 |
],
|
| 64 |
)
|
| 65 |
|
| 66 |
-
|
| 67 |
if __name__ == "__main__":
|
| 68 |
-
demo.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Initialize the text generation pipeline
|
| 5 |
+
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def respond(
|
|
|
|
| 27 |
|
| 28 |
messages.append({"role": "user", "content": template_instruction})
|
| 29 |
|
| 30 |
+
# Convert messages to a single prompt
|
| 31 |
+
user_messages = "\n".join([msg["content"] for msg in messages if msg["role"] == "user"])
|
| 32 |
+
system_message_content = next(msg["content"] for msg in messages if msg["role"] == "system")
|
| 33 |
|
| 34 |
+
prompt = f"{system_message_content}\n{user_messages}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
response = ""
|
| 37 |
+
# Generate text using the pipeline
|
| 38 |
+
outputs = pipe(prompt, max_length=max_tokens, do_sample=True, temperature=temperature, top_p=top_p)
|
| 39 |
+
generated_text = outputs[0]['generated_text']
|
| 40 |
+
|
| 41 |
+
# Yield the response token by token
|
| 42 |
+
for token in generated_text.split():
|
| 43 |
+
response += token + " "
|
| 44 |
yield response
|
| 45 |
|
| 46 |
"""
|
|
|
|
| 51 |
additional_inputs=[
|
| 52 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 53 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 54 |
+
gr.Slider(minimum=0.1, maximum 4.0, value=0.7, step=0.1, label="Temperature"),
|
| 55 |
gr.Slider(
|
| 56 |
minimum=0.1,
|
| 57 |
maximum=1.0,
|
|
|
|
| 63 |
],
|
| 64 |
)
|
| 65 |
|
|
|
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
demo.launch(share=True)
|