Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,38 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
-
from components.
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
)
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
st.sidebar.title("OpenAI API Key")
|
21 |
-
api_key = st.sidebar.text_input("Enter your OpenAI API key:", type='password')
|
22 |
|
23 |
-
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
"
|
42 |
-
default_index=0
|
43 |
-
)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|