Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,8 +50,6 @@ def respond(
|
|
50 |
max_tokens,
|
51 |
temperature,
|
52 |
top_p,
|
53 |
-
filename,
|
54 |
-
file_format
|
55 |
):
|
56 |
messages = [{"role": "system", "content": system_message}]
|
57 |
|
@@ -77,35 +75,41 @@ def respond(
|
|
77 |
response += token
|
78 |
yield response
|
79 |
|
80 |
-
|
|
|
|
|
|
|
81 |
saved_file = save_file(response, filename, file_format)
|
82 |
-
|
83 |
-
|
84 |
-
# Gradio interface
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
demo.launch()
|
|
|
50 |
max_tokens,
|
51 |
temperature,
|
52 |
top_p,
|
|
|
|
|
53 |
):
|
54 |
messages = [{"role": "system", "content": system_message}]
|
55 |
|
|
|
75 |
response += token
|
76 |
yield response
|
77 |
|
78 |
+
return response, history + [(message, response)]
|
79 |
+
|
80 |
+
# Function to handle file saving after generation
|
81 |
+
def save_generated_file(response, filename, file_format):
|
82 |
saved_file = save_file(response, filename, file_format)
|
83 |
+
return saved_file
|
84 |
+
|
85 |
+
# Gradio interface using Blocks
|
86 |
+
with gr.Blocks(css=css) as demo:
|
87 |
+
system_message = gr.Textbox(value="", label="System message")
|
88 |
+
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
89 |
+
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
90 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
|
91 |
+
filename = gr.Textbox(value="output", label="Filename")
|
92 |
+
file_format = gr.Radio(["pdf", "docx", "txt"], label="File Format", value="pdf")
|
93 |
+
|
94 |
+
message = gr.Textbox(label="User Message")
|
95 |
+
chat_history = gr.State(value=[])
|
96 |
+
response_output = gr.Textbox(label="Generated Response")
|
97 |
+
file_output = gr.File(label="Download File")
|
98 |
+
|
99 |
+
generate_button = gr.Button("Generate")
|
100 |
+
save_button = gr.Button("Save to File")
|
101 |
+
|
102 |
+
generate_button.click(
|
103 |
+
respond,
|
104 |
+
inputs=[message, chat_history, system_message, max_tokens, temperature, top_p],
|
105 |
+
outputs=[response_output, chat_history]
|
106 |
+
)
|
107 |
+
|
108 |
+
save_button.click(
|
109 |
+
save_generated_file,
|
110 |
+
inputs=[response_output, filename, file_format],
|
111 |
+
outputs=[file_output]
|
112 |
+
)
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
demo.launch()
|