JSenkCC commited on
Commit
ce69630
·
verified ·
1 Parent(s): 3754c82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -384,8 +384,7 @@ def extract_functions(gemini_output):
384
 
385
  def validate_and_generate_documentation(api_url, headers, gemini_output, file_contents, functionality_description):
386
  """
387
- Uses the Hugging Face Inference API to generate documentation based on Gemini output.
388
- Ensures that the output matches the expected format without unnecessary details.
389
  """
390
  # Generate the refined prompt for the Qwen model
391
  prompt = f"""
@@ -421,27 +420,42 @@ def validate_and_generate_documentation(api_url, headers, gemini_output, file_co
421
  """
422
 
423
  # Send the prompt to the Hugging Face API
424
- payload = {"inputs": prompt}
425
  response = requests.post(api_url, headers=headers, json=payload)
426
 
427
- # Handle the API response
428
  if response.status_code == 200:
429
  api_response = response.json()
430
- if isinstance(api_response, list): # If response is a list, extract the first element
431
- output = api_response[0].get("generated_text", "No output generated.")
432
- elif isinstance(api_response, dict): # Handle dict response
433
- output = api_response.get("generated_text", "No output generated.")
434
- else:
435
- raise ValueError("Unexpected response format from Hugging Face API.")
436
-
437
- # Clean the output to exclude any unnecessary details
438
- return output
439
- else:
440
- raise ValueError(f"Error: {response.status_code}, {response.text}")
441
 
 
442
 
 
 
 
443
 
 
 
 
444
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  def generate_documentation_page():
447
  st.subheader(f"Generate Documentation for {st.session_state.current_project}")
@@ -494,6 +508,7 @@ def generate_documentation_page():
494
 
495
 
496
 
 
497
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------
498
 
499
 
 
384
 
385
  def validate_and_generate_documentation(api_url, headers, gemini_output, file_contents, functionality_description):
386
  """
387
+ Uses the Hugging Face Inference API to generate complete documentation without truncation or prompts.
 
388
  """
389
  # Generate the refined prompt for the Qwen model
390
  prompt = f"""
 
420
  """
421
 
422
  # Send the prompt to the Hugging Face API
423
+ payload = {"inputs": prompt, "parameters": {"max_new_tokens": 2048}}
424
  response = requests.post(api_url, headers=headers, json=payload)
425
 
 
426
  if response.status_code == 200:
427
  api_response = response.json()
428
+ full_output = ""
429
+
430
+ # Handle multi-part outputs by looping until all content is retrieved
431
+ while isinstance(api_response, list) or isinstance(api_response, dict):
432
+ if isinstance(api_response, list):
433
+ output = api_response[0].get("generated_text", "")
434
+ elif isinstance(api_response, dict):
435
+ output = api_response.get("generated_text", "")
436
+ else:
437
+ break
 
438
 
439
+ full_output += output
440
 
441
+ # If the response indicates more content, request the next chunk
442
+ if "end_of_text" in output or len(output.strip()) == 0:
443
+ break
444
 
445
+ # Prepare the payload for continuation
446
+ payload = {"inputs": full_output, "parameters": {"max_new_tokens": 2048}}
447
+ response = requests.post(api_url, headers=headers, json=payload)
448
 
449
+ if response.status_code == 200:
450
+ api_response = response.json()
451
+ else:
452
+ raise ValueError(f"Error during continuation: {response.status_code}, {response.text}")
453
+
454
+ # Clean the output to exclude prompts
455
+ cleaned_output = clean_output(full_output)
456
+ return cleaned_output
457
+ else:
458
+ raise ValueError(f"Error: {response.status_code}, {response.text}")
459
 
460
  def generate_documentation_page():
461
  st.subheader(f"Generate Documentation for {st.session_state.current_project}")
 
508
 
509
 
510
 
511
+
512
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------
513
 
514