acecalisto3 commited on
Commit
fd7017c
·
verified ·
1 Parent(s): 062870d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -67
app.py CHANGED
@@ -1,73 +1,38 @@
1
- import streamlit as st
2
- import os
3
 
4
- # Import components and pages
5
- from components.code_documentation_page import home, refactor_page, style_page, test_page, \
6
- lang_page, code_documentation_page, database_page, optimize_page, \
7
- model_trainer_page, notebook_integration_page, xai_page, \
8
- versioning_tracker_page, nlp_nlg_page, devops_page, api_doc_page, \
9
- code_review_page, version_control_page, recommendation_system_page, \
10
- code_security_scanner_page, code_diagram_page
 
11
 
12
- # Initialize the app
13
- st.set_page_config(
14
- page_title="Codecrafter GPT: A Comprehensive Code Enhancement Platform",
15
- page_icon="🚀",
16
- layout="wide"
17
- )
 
 
 
18
 
19
- # Initialize the sidebar
20
- st.sidebar.title("OpenAI API Key")
21
- api_key = st.sidebar.text_input("Enter your OpenAI API key:", type='password')
22
 
23
- if not api_key:
24
- st.warning("Please enter your OpenAI API key to access pages.")
25
- else:
26
- # Instantiate the ChatOpenAI object
27
- from langchain.chat_models import ChatOpenAI
28
- chat = ChatOpenAI(
29
- model="gpt-3.5-turbo-16k",
30
- temperature=0,
31
- api_key=api_key
32
- )
33
 
34
- # Show the navigation menu
35
- selected = st.sidebar.select_icon("fa-icon",
36
- ["Home", "RefactorRite", "StyleSculpt", "TestGenius", "LangLink",
37
- "CodeDocGenius", "Database", "AutoOptimizer", "ModelTrainer",
38
- "NotebookIntegration", "ExplainableAI", "DataVersioning",
39
- "NLPandNLG", "DevOps", "APIDocGen", "CodeReviewAssistant",
40
- "VersionControl", "RecommendationSystem", "CodeSecurityScanner",
41
- "CodeDiagramConverter"],
42
- default_index=0
43
- )
44
 
45
- # Define a dictionary mapping page names to their corresponding functions
46
- pages = {
47
- "Home": home.show_home_page,
48
- "RefactorRite": refactor_page.show_refactor_page,
49
- "StyleSculpt": style_page.show_style_page,
50
- "TestGenius": test_page.show_test_page,
51
- "LangLink": lang_page.show_lang_page,
52
- "CodeDocGenius": code_documentation_page.show_doc_page,
53
- "Database": database_page.show_database_page,
54
- "AutoOptimizer": optimize_page.show_optimize_page,
55
- "ModelTrainer": model_trainer_page.show_model_trainer_page,
56
- "NotebookIntegration": notebook_integration_page.show_notebook_integration_page,
57
- "ExplainableAI": xai_page.show_xai_page,
58
- "DataVersioning": versioning_tracker_page.show_versioning_page,
59
- "NLPandNLG": nlp_nlg_page.show_nlp_nlg_page,
60
- "DevOps": devops_page.show_devops_page,
61
- "APIDocGen": api_doc_page.show_api_doc_page,
62
- "CodeReviewAssistant": code_review_page.show_code_review_page,
63
- "VersionControl": version_control_page.show_version_control_page,
64
- "RecommendationSystem": recommendation_system_page.show_recommendation_system_page,
65
- "CodeSecurityScanner": code_security_scanner_page.show_code_security_page,
66
- "CodeDiagramConverter": code_diagram_page.show_code_diagram_page
67
- }
68
-
69
- # Call the function for the selected page
70
- if selected in pages:
71
- pages[selected](chat)
72
- else:
73
- st.error("Page not found!")
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ from components.database_page import database_page
5
+ from components.documentation_page import documentation_page
6
+ from components.home import home
7
+ from components.lang_page import lang_page
8
+ from components.optimization_page import optimization_page
9
+ from components.refactor_page import refactor_page
10
+ from components.style_page import style_page
11
+ from components.test_page import test_page
12
 
13
+ # Gradio interface
14
+ def setup_interface():
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("### Select Model and Task")
17
+ with gr.Row():
18
+ model_name = gr.Dropdown(label="Model", choices=["gpt2", "bert-base-uncased"])
19
+ task = gr.Dropdown(label="Task", choices=["text-generation", "text-classification"])
20
+ input_data = gr.Textbox(label="Input")
21
+ output = gr.Textbox(label="Output")
22
 
23
+ input_data.change(fn=model_inference, inputs=[model_name, task, input_data], outputs=output)
 
 
24
 
25
+ return demo
 
 
 
 
 
 
 
 
 
26
 
27
+ # Function to generate text or perform other tasks based on model selection
28
+ def model_inference(model_name, task, input_data):
29
+ try:
30
+ model_pipeline = pipeline(task, model=model_name)
31
+ result = model_pipeline(input_data)
32
+ return result
33
+ except Exception as e:
34
+ return f"Error: {e}"
 
 
35
 
36
+ if __name__ == "__main__":
37
+ interface = setup_interface()
38
+ interface.launch()