Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load models
|
| 5 |
code_analyzer = pipeline("text-classification", model="microsoft/codebert-base")
|
| 6 |
-
nlp_model = pipeline("text2text-generation", model="google/flan-t5-
|
| 7 |
|
| 8 |
# Code Review Function
|
| 9 |
def analyze_code(code):
|
|
@@ -12,17 +12,17 @@ def analyze_code(code):
|
|
| 12 |
result = code_analyzer(code)
|
| 13 |
return result[0]["label"], "Consider refactoring for better performance", "Medium"
|
| 14 |
|
| 15 |
-
# Metadata Validator (Mock
|
| 16 |
def validate_metadata(metadata):
|
| 17 |
if not metadata.strip():
|
| 18 |
return "No metadata provided.", "", ""
|
| 19 |
return "Field", "Unused field detected", "Remove it to improve performance"
|
| 20 |
|
| 21 |
-
# Natural Language Processor (
|
| 22 |
def process_nlp_query(query):
|
| 23 |
if not query.strip():
|
| 24 |
return "No query provided."
|
| 25 |
-
result = nlp_model(query, max_length=
|
| 26 |
return result[0]["generated_text"]
|
| 27 |
|
| 28 |
# Gradio UI
|
|
@@ -46,7 +46,7 @@ with gr.Blocks() as demo:
|
|
| 46 |
metadata_button.click(validate_metadata, inputs=metadata_input, outputs=[mtype, issue, recommendation])
|
| 47 |
|
| 48 |
with gr.Tab("Ask AI (Natural Language)"):
|
| 49 |
-
query_input = gr.Textbox(label="Your question", lines=2, placeholder="e.g.
|
| 50 |
response_output = gr.Textbox(label="AI Response")
|
| 51 |
nlp_button = gr.Button("Ask")
|
| 52 |
nlp_button.click(process_nlp_query, inputs=query_input, outputs=response_output)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load models (optimized for performance)
|
| 5 |
code_analyzer = pipeline("text-classification", model="microsoft/codebert-base")
|
| 6 |
+
nlp_model = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 7 |
|
| 8 |
# Code Review Function
|
| 9 |
def analyze_code(code):
|
|
|
|
| 12 |
result = code_analyzer(code)
|
| 13 |
return result[0]["label"], "Consider refactoring for better performance", "Medium"
|
| 14 |
|
| 15 |
+
# Metadata Validator (Mock)
|
| 16 |
def validate_metadata(metadata):
|
| 17 |
if not metadata.strip():
|
| 18 |
return "No metadata provided.", "", ""
|
| 19 |
return "Field", "Unused field detected", "Remove it to improve performance"
|
| 20 |
|
| 21 |
+
# Natural Language Processor (faster)
|
| 22 |
def process_nlp_query(query):
|
| 23 |
if not query.strip():
|
| 24 |
return "No query provided."
|
| 25 |
+
result = nlp_model(query, max_length=50, do_sample=False)
|
| 26 |
return result[0]["generated_text"]
|
| 27 |
|
| 28 |
# Gradio UI
|
|
|
|
| 46 |
metadata_button.click(validate_metadata, inputs=metadata_input, outputs=[mtype, issue, recommendation])
|
| 47 |
|
| 48 |
with gr.Tab("Ask AI (Natural Language)"):
|
| 49 |
+
query_input = gr.Textbox(label="Your question", lines=2, placeholder="e.g. How to optimize SOQL?")
|
| 50 |
response_output = gr.Textbox(label="AI Response")
|
| 51 |
nlp_button = gr.Button("Ask")
|
| 52 |
nlp_button.click(process_nlp_query, inputs=query_input, outputs=response_output)
|