|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
st.set_page_config(page_title="ML Assistant with Replit LLM", layout="wide") |
|
st.title("🤖 ML Assistant with Replit LLM") |
|
st.write("Interact with the Replit LLM for machine learning workflows and AI-driven coding assistance.") |
|
|
|
|
|
st.sidebar.title("Configuration") |
|
api_key = st.sidebar.text_input("Replit LLM API Key", type="password") |
|
model_name = st.sidebar.text_input("Hugging Face Model Name", "Canstralian/RabbitRedux") |
|
task_type = st.sidebar.selectbox( |
|
"Choose a Task", |
|
["Text Generation", "Pseudocode to Python", "ML Debugging", "Code Optimization"] |
|
) |
|
|
|
|
|
if not api_key: |
|
st.warning("Please provide your Replit LLM API Key in the sidebar to continue.") |
|
st.stop() |
|
|
|
|
|
try: |
|
nlp_pipeline = pipeline("text2text-generation", model=model_name) |
|
st.success("Model loaded successfully!") |
|
except Exception as e: |
|
st.error(f"Error loading model: {e}") |
|
st.stop() |
|
|
|
|
|
st.subheader("Input Your Query") |
|
user_input = st.text_area("Enter your query or task description", height=150) |
|
|
|
|
|
if st.button("Generate Output"): |
|
if user_input.strip() == "": |
|
st.warning("Please enter a valid input.") |
|
else: |
|
with st.spinner("Processing..."): |
|
try: |
|
|
|
output = nlp_pipeline(user_input) |
|
response = output[0]["generated_text"] |
|
st.subheader("AI Response") |
|
st.write(response) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|
|
|
|
st.subheader("Advanced Machine Learning Assistance") |
|
|
|
if task_type == "Text Generation": |
|
st.info("Use the input box to generate text-based output.") |
|
elif task_type == "Pseudocode to Python": |
|
st.info("Provide pseudocode, and the Replit LLM will attempt to generate Python code.") |
|
example = st.button("Show Example") |
|
if example: |
|
st.code(""" |
|
# Pseudocode |
|
FOR each item IN list: |
|
IF item > threshold: |
|
PRINT "Above Threshold" |
|
|
|
# Expected Python Output |
|
for item in my_list: |
|
if item > threshold: |
|
print("Above Threshold") |
|
""") |
|
elif task_type == "ML Debugging": |
|
st.info("Describe your ML pipeline error for debugging suggestions.") |
|
elif task_type == "Code Optimization": |
|
st.info("Paste your Python code for optimization recommendations.") |
|
user_code = st.text_area("Paste your Python code", height=200) |
|
if st.button("Optimize Code"): |
|
with st.spinner("Analyzing and optimizing..."): |
|
try: |
|
optimization_prompt = f"Optimize the following Python code:\n\n{user_code}" |
|
output = nlp_pipeline(optimization_prompt) |
|
optimized_code = output[0]["generated_text"] |
|
st.subheader("Optimized Code") |
|
st.code(optimized_code) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|
|
|
|
st.write("---") |
|
st.write("Powered by [Replit LLM](https://replit.com) and [Hugging Face](https://huggingface.co).") |
|
|