Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import requests
|
|
| 8 |
def call_groq_api(data, user_prompt):
|
| 9 |
api_url = "https://api.groq.example/modify" # Replace with your Groq API URL
|
| 10 |
headers = {
|
| 11 |
-
"Authorization": "Bearer
|
| 12 |
"Content-Type": "application/json"
|
| 13 |
}
|
| 14 |
payload = {
|
|
@@ -26,18 +26,18 @@ def call_groq_api(data, user_prompt):
|
|
| 26 |
return f"Error connecting to Groq API: {str(e)}"
|
| 27 |
|
| 28 |
# Function to process uploaded files
|
| 29 |
-
def process_file(
|
| 30 |
-
if not
|
| 31 |
return "No file uploaded.", None
|
| 32 |
|
| 33 |
try:
|
| 34 |
# Check file type and extract data
|
| 35 |
-
if
|
| 36 |
-
df = pd.read_excel(
|
| 37 |
data = df.to_string(index=False)
|
| 38 |
-
elif
|
| 39 |
data = ""
|
| 40 |
-
with pdfplumber.open(
|
| 41 |
for page in pdf.pages:
|
| 42 |
data += page.extract_text()
|
| 43 |
else:
|
|
@@ -65,7 +65,7 @@ def gradio_interface():
|
|
| 65 |
with gr.Blocks() as app:
|
| 66 |
gr.Markdown("## Upload an Excel or PDF File and Modify with a Prompt")
|
| 67 |
with gr.Row():
|
| 68 |
-
file_input = gr.File(label="Upload File", type="
|
| 69 |
user_prompt = gr.Textbox(label="Enter Prompt to Modify Data")
|
| 70 |
output_msg = gr.Textbox(label="Processing Status")
|
| 71 |
file_output = gr.File(label="Download Updated PDF")
|
|
@@ -78,7 +78,7 @@ def gradio_interface():
|
|
| 78 |
)
|
| 79 |
return app
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
if __name__ == "__main__":
|
|
|
|
| 84 |
app.launch()
|
|
|
|
| 8 |
def call_groq_api(data, user_prompt):
|
| 9 |
api_url = "https://api.groq.example/modify" # Replace with your Groq API URL
|
| 10 |
headers = {
|
| 11 |
+
"Authorization": "Bearer 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", # Replace with your API token
|
| 12 |
"Content-Type": "application/json"
|
| 13 |
}
|
| 14 |
payload = {
|
|
|
|
| 26 |
return f"Error connecting to Groq API: {str(e)}"
|
| 27 |
|
| 28 |
# Function to process uploaded files
|
| 29 |
+
def process_file(file_path, user_prompt):
|
| 30 |
+
if not file_path:
|
| 31 |
return "No file uploaded.", None
|
| 32 |
|
| 33 |
try:
|
| 34 |
# Check file type and extract data
|
| 35 |
+
if file_path.endswith(".xlsx") or file_path.endswith(".xls"):
|
| 36 |
+
df = pd.read_excel(file_path)
|
| 37 |
data = df.to_string(index=False)
|
| 38 |
+
elif file_path.endswith(".pdf"):
|
| 39 |
data = ""
|
| 40 |
+
with pdfplumber.open(file_path) as pdf:
|
| 41 |
for page in pdf.pages:
|
| 42 |
data += page.extract_text()
|
| 43 |
else:
|
|
|
|
| 65 |
with gr.Blocks() as app:
|
| 66 |
gr.Markdown("## Upload an Excel or PDF File and Modify with a Prompt")
|
| 67 |
with gr.Row():
|
| 68 |
+
file_input = gr.File(label="Upload File", type="filepath") # Fixed type
|
| 69 |
user_prompt = gr.Textbox(label="Enter Prompt to Modify Data")
|
| 70 |
output_msg = gr.Textbox(label="Processing Status")
|
| 71 |
file_output = gr.File(label="Download Updated PDF")
|
|
|
|
| 78 |
)
|
| 79 |
return app
|
| 80 |
|
| 81 |
+
# Launch the app
|
|
|
|
| 82 |
if __name__ == "__main__":
|
| 83 |
+
app = gradio_interface()
|
| 84 |
app.launch()
|