lodhrangpt commited on
Commit
3b8a435
·
verified ·
1 Parent(s): 4428460

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
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 YOUR_API_TOKEN", # Replace with your API token
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(file, user_prompt):
30
- if not file:
31
  return "No file uploaded.", None
32
 
33
  try:
34
  # Check file type and extract data
35
- if file.name.endswith(".xlsx") or file.name.endswith(".xls"):
36
- df = pd.read_excel(file.name)
37
  data = df.to_string(index=False)
38
- elif file.name.endswith(".pdf"):
39
  data = ""
40
- with pdfplumber.open(file.name) as pdf:
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="file")
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
- app = gradio_interface()
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()