Update app.py
Browse files
app.py
CHANGED
@@ -391,8 +391,8 @@ def validate_and_generate_documentation(api_url, headers, gemini_output, functio
|
|
391 |
"""
|
392 |
Uses the Hugging Face Inference API to generate clean and relevant documentation using Qwen.
|
393 |
"""
|
|
|
394 |
cleaned_gemini_output = extract_cleaned_gemini_output(gemini_output)
|
395 |
-
gemini_output_length = len(cleaned_gemini_output) # Record the length of the cleaned Gemini output
|
396 |
|
397 |
# Generate the refined prompt for Qwen
|
398 |
prompt = f"""
|
@@ -433,8 +433,6 @@ def validate_and_generate_documentation(api_url, headers, gemini_output, functio
|
|
433 |
5. Return only the required information for the above tasks, and exclude everything else.
|
434 |
"""
|
435 |
|
436 |
-
qwen_prompt_length = len(prompt)
|
437 |
-
|
438 |
payload = {"inputs": prompt, "parameters": {"max_new_tokens": 1024}}
|
439 |
response = requests.post(api_url, headers=headers, json=payload)
|
440 |
|
@@ -443,14 +441,23 @@ def validate_and_generate_documentation(api_url, headers, gemini_output, functio
|
|
443 |
api_response = response.json()
|
444 |
output = api_response.get("generated_text", "") if isinstance(api_response, dict) else api_response[0].get("generated_text", "")
|
445 |
|
446 |
-
#
|
447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
|
449 |
-
|
|
|
450 |
else:
|
451 |
raise ValueError(f"Error during API call: {response.status_code}, {response.text}")
|
452 |
|
453 |
|
|
|
454 |
def generate_documentation_page():
|
455 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
456 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
|
|
391 |
"""
|
392 |
Uses the Hugging Face Inference API to generate clean and relevant documentation using Qwen.
|
393 |
"""
|
394 |
+
# Clean Gemini output
|
395 |
cleaned_gemini_output = extract_cleaned_gemini_output(gemini_output)
|
|
|
396 |
|
397 |
# Generate the refined prompt for Qwen
|
398 |
prompt = f"""
|
|
|
433 |
5. Return only the required information for the above tasks, and exclude everything else.
|
434 |
"""
|
435 |
|
|
|
|
|
436 |
payload = {"inputs": prompt, "parameters": {"max_new_tokens": 1024}}
|
437 |
response = requests.post(api_url, headers=headers, json=payload)
|
438 |
|
|
|
441 |
api_response = response.json()
|
442 |
output = api_response.get("generated_text", "") if isinstance(api_response, dict) else api_response[0].get("generated_text", "")
|
443 |
|
444 |
+
# Extract only the relevant sections by identifying key markers in the output
|
445 |
+
relevant_sections = []
|
446 |
+
capturing = False
|
447 |
+
|
448 |
+
for line in output.splitlines():
|
449 |
+
if "Project Summary:" in line or "Functionality Summary:" in line or "Functionality Flow:" in line or "Function Documentation:" in line:
|
450 |
+
capturing = True # Start capturing from relevant sections
|
451 |
+
if capturing:
|
452 |
+
relevant_sections.append(line)
|
453 |
|
454 |
+
# Join relevant sections and perform final cleanup
|
455 |
+
return clean_output("\n".join(relevant_sections))
|
456 |
else:
|
457 |
raise ValueError(f"Error during API call: {response.status_code}, {response.text}")
|
458 |
|
459 |
|
460 |
+
|
461 |
def generate_documentation_page():
|
462 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
463 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|