Spaces:
Sleeping
Sleeping
karwanjiru
commited on
Commit
•
46e83b2
1
Parent(s):
b96f71d
..
Browse files
app.py
CHANGED
@@ -8,8 +8,8 @@ from io import BytesIO
|
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
# Define the function to respond to user inputs
|
11 |
-
def respond(message, history):
|
12 |
-
messages = []
|
13 |
|
14 |
for val in history:
|
15 |
if val[0]:
|
@@ -21,14 +21,20 @@ def respond(message, history):
|
|
21 |
|
22 |
response = client.chat_completion(
|
23 |
messages,
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
return response.choices[0].message['content']
|
27 |
|
28 |
# Define the function to generate posts
|
29 |
-
def generate_post(prompt):
|
30 |
response = client.chat_completion(
|
31 |
[{"role": "user", "content": prompt}],
|
|
|
|
|
|
|
32 |
)
|
33 |
return response.choices[0].message['content']
|
34 |
|
@@ -77,6 +83,12 @@ with demo:
|
|
77 |
with gr.Column():
|
78 |
chat_interface = gr.ChatInterface(
|
79 |
respond,
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
)
|
81 |
advanced_button = gr.Button("Show Advanced Settings")
|
82 |
advanced_settings = gr.Column(visible=False)
|
@@ -93,9 +105,12 @@ with demo:
|
|
93 |
|
94 |
with gr.TabItem("Generate Post"):
|
95 |
post_prompt = gr.Textbox(label="Post Prompt")
|
|
|
|
|
|
|
96 |
generate_button = gr.Button("Generate Post")
|
97 |
generated_post = gr.Textbox(label="Generated Post")
|
98 |
-
generate_button.click(generate_post, post_prompt, generated_post)
|
99 |
|
100 |
with gr.TabItem("Moderate Post"):
|
101 |
post_content = gr.Textbox(label="Post Content")
|
@@ -115,5 +130,5 @@ with demo:
|
|
115 |
image_moderation_result = gr.Textbox(label="Image Moderation Result")
|
116 |
moderate_image_button.click(moderate_image, uploaded_image, image_moderation_result)
|
117 |
|
118 |
-
if __name__ == "__main__":
|
119 |
-
demo.launch(
|
|
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
# Define the function to respond to user inputs
|
11 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
12 |
+
messages = [{"role": "system", "content": system_message}]
|
13 |
|
14 |
for val in history:
|
15 |
if val[0]:
|
|
|
21 |
|
22 |
response = client.chat_completion(
|
23 |
messages,
|
24 |
+
max_tokens=max_tokens,
|
25 |
+
temperature=temperature,
|
26 |
+
top_p=top_p,
|
27 |
)
|
28 |
|
29 |
return response.choices[0].message['content']
|
30 |
|
31 |
# Define the function to generate posts
|
32 |
+
def generate_post(prompt, max_tokens, temperature, top_p):
|
33 |
response = client.chat_completion(
|
34 |
[{"role": "user", "content": prompt}],
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
temperature=temperature,
|
37 |
+
top_p=top_p,
|
38 |
)
|
39 |
return response.choices[0].message['content']
|
40 |
|
|
|
83 |
with gr.Column():
|
84 |
chat_interface = gr.ChatInterface(
|
85 |
respond,
|
86 |
+
additional_inputs=[
|
87 |
+
gr.Textbox(value="You are a friendly Chatbot meant to assist users in managing social media posts ensuring they meet community guidelines", label="System message", visible=False),
|
88 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens", visible=False),
|
89 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature", visible=False),
|
90 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)", visible=False),
|
91 |
+
],
|
92 |
)
|
93 |
advanced_button = gr.Button("Show Advanced Settings")
|
94 |
advanced_settings = gr.Column(visible=False)
|
|
|
105 |
|
106 |
with gr.TabItem("Generate Post"):
|
107 |
post_prompt = gr.Textbox(label="Post Prompt")
|
108 |
+
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
109 |
+
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
110 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
111 |
generate_button = gr.Button("Generate Post")
|
112 |
generated_post = gr.Textbox(label="Generated Post")
|
113 |
+
generate_button.click(generate_post, [post_prompt, max_tokens, temperature, top_p], generated_post)
|
114 |
|
115 |
with gr.TabItem("Moderate Post"):
|
116 |
post_content = gr.Textbox(label="Post Content")
|
|
|
130 |
image_moderation_result = gr.Textbox(label="Image Moderation Result")
|
131 |
moderate_image_button.click(moderate_image, uploaded_image, image_moderation_result)
|
132 |
|
133 |
+
if __name__ == "__main__":
|
134 |
+
demo.launch()
|