Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ import requests
|
|
11 |
from fpdf import FPDF
|
12 |
import markdown
|
13 |
import tempfile
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
# Database setup
|
@@ -205,8 +208,6 @@ def workspace_page():
|
|
205 |
except Exception as e:
|
206 |
st.error(f"Failed to clone repository: {e}")
|
207 |
|
208 |
-
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
209 |
-
|
210 |
|
211 |
# Configure Gemini API
|
212 |
gemini = os.getenv("GEMINI")
|
@@ -468,6 +469,26 @@ def generate_documentation_page():
|
|
468 |
# Display the final documentation
|
469 |
st.success("Documentation generated successfully!")
|
470 |
st.text_area("Generated Documentation", documentation, height=600)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
except Exception as e:
|
472 |
st.error(f"An error occurred: {e}")
|
473 |
else:
|
@@ -475,6 +496,8 @@ def generate_documentation_page():
|
|
475 |
else:
|
476 |
st.error("Please enter the functionality to analyze.")
|
477 |
|
|
|
|
|
478 |
# Add export/download buttons if documentation is available
|
479 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
480 |
documentation = st.session_state.generated_documentation
|
@@ -587,6 +610,73 @@ def generate_markdown_file(documentation, output_path):
|
|
587 |
with open(output_path, "w") as f:
|
588 |
f.write("\n".join(formatted_lines))
|
589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
|
591 |
|
592 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
11 |
from fpdf import FPDF
|
12 |
import markdown
|
13 |
import tempfile
|
14 |
+
import re
|
15 |
+
import spacy
|
16 |
+
from collections import defaultdict
|
17 |
|
18 |
|
19 |
# Database setup
|
|
|
208 |
except Exception as e:
|
209 |
st.error(f"Failed to clone repository: {e}")
|
210 |
|
|
|
|
|
211 |
|
212 |
# Configure Gemini API
|
213 |
gemini = os.getenv("GEMINI")
|
|
|
469 |
# Display the final documentation
|
470 |
st.success("Documentation generated successfully!")
|
471 |
st.text_area("Generated Documentation", documentation, height=600)
|
472 |
+
|
473 |
+
#---------------------------------------------------------------------------
|
474 |
+
# Example Gemini output for testing
|
475 |
+
test_gemini_output = """
|
476 |
+
Functionality Summary:
|
477 |
+
Authenticate the user by verifying their credentials. Once authenticated, fetch user-specific data such as preferences and usage history. Handle errors during both authentication and data retrieval.
|
478 |
+
|
479 |
+
Project Summary:
|
480 |
+
<Some project details>
|
481 |
+
|
482 |
+
Functionality Flow:
|
483 |
+
<Flow details>
|
484 |
+
"""
|
485 |
+
|
486 |
+
# Streamlit testing
|
487 |
+
if "page" not in st.session_state or st.session_state.page == "test_functionality":
|
488 |
+
st.title("Test Functionality Extraction")
|
489 |
+
display_functionality_analysis(test_gemini_output)
|
490 |
+
#---------------------------------------------------------------------------
|
491 |
+
|
492 |
except Exception as e:
|
493 |
st.error(f"An error occurred: {e}")
|
494 |
else:
|
|
|
496 |
else:
|
497 |
st.error("Please enter the functionality to analyze.")
|
498 |
|
499 |
+
|
500 |
+
|
501 |
# Add export/download buttons if documentation is available
|
502 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
503 |
documentation = st.session_state.generated_documentation
|
|
|
610 |
with open(output_path, "w") as f:
|
611 |
f.write("\n".join(formatted_lines))
|
612 |
|
613 |
+
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
614 |
+
|
615 |
+
# Load the NLP model (use the small model for speed)
|
616 |
+
nlp = spacy.load("en_core_web_sm")
|
617 |
+
|
618 |
+
def extract_functionality_and_relationships(gemini_output):
|
619 |
+
"""
|
620 |
+
Extracts functionality descriptions and sub-functionality relationships from Gemini output.
|
621 |
+
Args:
|
622 |
+
gemini_output (str): The raw output from Gemini.
|
623 |
+
Returns:
|
624 |
+
dict: A dictionary with functionality and its relationships.
|
625 |
+
"""
|
626 |
+
functionality_summary = None
|
627 |
+
relationships = defaultdict(list)
|
628 |
+
|
629 |
+
# Extract the 'Functionality Summary' section
|
630 |
+
functionality_match = re.search(r"Functionality Summary:\n(.*?)\n\n", gemini_output, re.DOTALL)
|
631 |
+
if functionality_match:
|
632 |
+
functionality_summary = functionality_match.group(1).strip()
|
633 |
+
|
634 |
+
# Parse the functionality summary with NLP
|
635 |
+
if functionality_summary:
|
636 |
+
doc = nlp(functionality_summary)
|
637 |
+
|
638 |
+
# Extract relationships between sub-functionalities
|
639 |
+
for sentence in doc.sents:
|
640 |
+
sub_functionalities = []
|
641 |
+
for token in sentence:
|
642 |
+
# Capture sub-functionalities using noun chunks or proper nouns
|
643 |
+
if token.dep_ in {"nsubj", "dobj", "pobj"} or token.ent_type_ in {"ORG", "PRODUCT"}:
|
644 |
+
sub_functionalities.append(token.text)
|
645 |
+
if len(sub_functionalities) > 1:
|
646 |
+
# Create relationships between identified sub-functionalities
|
647 |
+
main_functionality = sub_functionalities[0]
|
648 |
+
for related in sub_functionalities[1:]:
|
649 |
+
relationships[main_functionality].append(related)
|
650 |
+
|
651 |
+
return functionality_summary, dict(relationships)
|
652 |
+
|
653 |
+
|
654 |
+
def display_functionality_analysis(gemini_output):
|
655 |
+
"""
|
656 |
+
Extracts and displays functionality analysis for testing purposes.
|
657 |
+
Args:
|
658 |
+
gemini_output (str): The raw output from Gemini.
|
659 |
+
"""
|
660 |
+
# Extract functionality and relationships
|
661 |
+
functionality, relationships = extract_functionality_and_relationships(gemini_output)
|
662 |
+
|
663 |
+
# Display extracted functionality
|
664 |
+
st.subheader("Extracted Functionality Summary")
|
665 |
+
if functionality:
|
666 |
+
st.text_area("Functionality Summary", functionality, height=200)
|
667 |
+
else:
|
668 |
+
st.error("No functionality summary found in the Gemini output.")
|
669 |
+
|
670 |
+
# Display extracted relationships
|
671 |
+
st.subheader("Extracted Relationships")
|
672 |
+
if relationships:
|
673 |
+
for main, related in relationships.items():
|
674 |
+
st.write(f"**{main}** is related to: {', '.join(related)}")
|
675 |
+
else:
|
676 |
+
st.info("No relationships between sub-functionalities identified.")
|
677 |
+
|
678 |
+
|
679 |
+
|
680 |
|
681 |
|
682 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|