Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import torch
|
4 |
-
import
|
5 |
|
6 |
-
# Load the model pipeline
|
7 |
-
|
8 |
-
pipeline = transformers.pipeline(
|
9 |
"text-generation",
|
10 |
-
model=
|
11 |
-
|
12 |
-
device_map="auto"
|
13 |
)
|
14 |
|
15 |
# Define the initial system message
|
@@ -55,17 +54,15 @@ def chat(user_input, messages):
|
|
55 |
messages.append({"role": "user", "content": user_input})
|
56 |
|
57 |
# Prepare the input for the model
|
58 |
-
input_text =
|
59 |
|
60 |
# Generate a response using the pipeline
|
61 |
try:
|
62 |
-
|
63 |
-
formatted_input = "\n".join([f"{msg['role']}: {msg['content']}" for msg in input_text])
|
64 |
-
response = pipeline(formatted_input, max_new_tokens=256)
|
65 |
|
66 |
# Extract the assistant's response
|
67 |
-
response_content = response[0][
|
68 |
-
|
69 |
# Store assistant response in the chat history
|
70 |
messages.append({"role": "assistant", "content": response_content})
|
71 |
|
@@ -77,7 +74,7 @@ def chat(user_input, messages):
|
|
77 |
|
78 |
# Gradio Interface
|
79 |
with gr.Blocks() as demo:
|
80 |
-
gr.Markdown("##
|
81 |
|
82 |
# Sidebar for user inputs
|
83 |
with gr.Row():
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import torch
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
+
# Load the Zephyr-7B-Beta model pipeline
|
7 |
+
pipe = pipeline(
|
|
|
8 |
"text-generation",
|
9 |
+
model="HuggingFaceH4/zephyr-7b-beta",
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto"
|
12 |
)
|
13 |
|
14 |
# Define the initial system message
|
|
|
54 |
messages.append({"role": "user", "content": user_input})
|
55 |
|
56 |
# Prepare the input for the model
|
57 |
+
input_text = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
58 |
|
59 |
# Generate a response using the pipeline
|
60 |
try:
|
61 |
+
response = pipe(input_text, max_new_tokens=256, return_full_text=False)
|
|
|
|
|
62 |
|
63 |
# Extract the assistant's response
|
64 |
+
response_content = response[0]['generated_text'].strip()
|
65 |
+
|
66 |
# Store assistant response in the chat history
|
67 |
messages.append({"role": "assistant", "content": response_content})
|
68 |
|
|
|
74 |
|
75 |
# Gradio Interface
|
76 |
with gr.Blocks() as demo:
|
77 |
+
gr.Markdown("## FRIDAY")
|
78 |
|
79 |
# Sidebar for user inputs
|
80 |
with gr.Row():
|