Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,28 @@ import requests
|
|
6 |
#Streaming endpoint
|
7 |
API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
|
8 |
|
9 |
-
def handle_file(file_path, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
#Inferenec function
|
@@ -150,10 +159,18 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
150 |
state = gr.State([])
|
151 |
|
152 |
# Add a file upload component for Python files
|
153 |
-
file_upload = gr.File(label="Upload Python File", type="file", placeholder="Upload a Python file to start the conversation with its content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
# Example modification for the input submission handler
|
156 |
inputs.submit(handle_file, inputs=[file_upload, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], outputs=[chatbot, state, chat_counter, server_status_code])
|
|
|
157 |
|
158 |
# inputs.submit(handle_file, [file_upload, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code])
|
159 |
# If you have a button for submission, modify its click handler similarly
|
|
|
6 |
#Streaming endpoint
|
7 |
API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
|
8 |
|
9 |
+
# def handle_file(file_path, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
10 |
+
# """
|
11 |
+
# New function to handle file content.
|
12 |
+
# Reads the uploaded Python file and uses its content in the conversation.
|
13 |
+
# """
|
14 |
+
# # Read the content of the uploaded file
|
15 |
+
# with open(file_path, "r") as file:
|
16 |
+
# file_content = file.read()
|
17 |
|
18 |
+
# # Use the content of the file as part of your conversation
|
19 |
+
# # For example, prepend the file content to the inputs or system message
|
20 |
+
# # Here, we'll just pass the file_content as the system message for simplicity
|
21 |
+
# return predict(openai_gpt4_key, file_content, inputs, top_p, temperature, chat_counter, chatbot, history)
|
22 |
+
|
23 |
+
def handle_file(file_info, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
24 |
+
if file_info is not None:
|
25 |
+
# Read the content of the uploaded file directly from the file_info object
|
26 |
+
file_content = file_info["content"].read().decode("utf-8")
|
27 |
+
# Use the content as needed, for example, as the system message
|
28 |
+
return predict(openai_gpt4_key, file_content, inputs, top_p, temperature, chat_counter, chatbot, history)
|
29 |
+
else:
|
30 |
+
return "No file uploaded."
|
31 |
|
32 |
|
33 |
#Inferenec function
|
|
|
159 |
state = gr.State([])
|
160 |
|
161 |
# Add a file upload component for Python files
|
162 |
+
# file_upload = gr.File(label="Upload Python File", type="file", placeholder="Upload a Python file to start the conversation with its content")
|
163 |
+
file_upload = gr.File(label="Upload Python File", type="file") # Removed 'placeholder' and corrected 'type'
|
164 |
+
|
165 |
+
#top_p, temperature
|
166 |
+
with gr.Accordion("Parameters", open=False):
|
167 |
+
top_p = gr.Slider( minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
|
168 |
+
temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
|
169 |
+
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
170 |
|
171 |
# Example modification for the input submission handler
|
172 |
inputs.submit(handle_file, inputs=[file_upload, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], outputs=[chatbot, state, chat_counter, server_status_code])
|
173 |
+
# inputs.submit(handle_file, inputs=[file_upload, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], outputs=[chatbot, state, chat_counter, server_status_code])
|
174 |
|
175 |
# inputs.submit(handle_file, [file_upload, openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code])
|
176 |
# If you have a button for submission, modify its click handler similarly
|