Canstralian commited on
Commit
dff0f84
·
verified ·
1 Parent(s): e7bac4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -59
app.py CHANGED
@@ -1,31 +1,9 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
-
4
- # App Title
5
- st.set_page_config(page_title="ML Assistant with Replit LLM", layout="wide")
6
- st.title("🤖 ML Assistant with Replit LLM")
7
- st.write("Interact with the Replit LLM for machine learning workflows and AI-driven coding assistance.")
8
-
9
- # Sidebar Configuration
10
- st.sidebar.title("Configuration")
11
- api_key = st.sidebar.text_input("Replit LLM API Key", type="password")
12
- model_name = st.sidebar.text_input("Hugging Face Model Name", "Canstralian/RabbitRedux")
13
- task_type = st.sidebar.selectbox(
14
- "Choose a Task",
15
- ["Text Generation", "Pseudocode to Python", "ML Debugging", "Code Optimization"]
16
- )
17
-
18
- # Ensure API Key is Provided
19
- if not api_key:
20
- st.warning("Please provide your Replit LLM API Key in the sidebar to continue.")
21
- st.stop()
22
-
23
  # Initialize Replit LLM Pipeline
24
  try:
25
  nlp_pipeline = pipeline("text2text-generation", model=model_name)
26
  st.success("Model loaded successfully!")
27
  except Exception as e:
28
- st.error(f"Error loading model: {e}")
29
  st.stop()
30
 
31
  # Input Section
@@ -47,42 +25,20 @@ if st.button("Generate Output"):
47
  except Exception as e:
48
  st.error(f"An error occurred: {e}")
49
 
50
- # Additional ML Features
51
- st.subheader("Advanced Machine Learning Assistance")
52
-
53
- if task_type == "Text Generation":
54
- st.info("Use the input box to generate text-based output.")
55
- elif task_type == "Pseudocode to Python":
56
- st.info("Provide pseudocode, and the Replit LLM will attempt to generate Python code.")
57
- example = st.button("Show Example")
58
- if example:
59
- st.code("""
60
- # Pseudocode
61
- FOR each item IN list:
62
- IF item > threshold:
63
- PRINT "Above Threshold"
64
-
65
- # Expected Python Output
66
- for item in my_list:
67
- if item > threshold:
68
- print("Above Threshold")
69
- """)
70
- elif task_type == "ML Debugging":
71
- st.info("Describe your ML pipeline error for debugging suggestions.")
72
- elif task_type == "Code Optimization":
73
  st.info("Paste your Python code for optimization recommendations.")
74
  user_code = st.text_area("Paste your Python code", height=200)
75
  if st.button("Optimize Code"):
76
- with st.spinner("Analyzing and optimizing..."):
77
- try:
78
- optimization_prompt = f"Optimize the following Python code:\n\n{user_code}"
79
- output = nlp_pipeline(optimization_prompt)
80
- optimized_code = output[0]["generated_text"]
81
- st.subheader("Optimized Code")
82
- st.code(optimized_code)
83
- except Exception as e:
84
- st.error(f"An error occurred: {e}")
85
-
86
- # Footer
87
- st.write("---")
88
- st.write("Powered by [Replit LLM](https://replit.com) and [Hugging Face](https://huggingface.co).")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Initialize Replit LLM Pipeline
2
  try:
3
  nlp_pipeline = pipeline("text2text-generation", model=model_name)
4
  st.success("Model loaded successfully!")
5
  except Exception as e:
6
+ st.error(f"Error loading model: {e}. Please verify the model name or your internet connection.")
7
  st.stop()
8
 
9
  # Input Section
 
25
  except Exception as e:
26
  st.error(f"An error occurred: {e}")
27
 
28
+ # Handling Code Optimization:
29
+ if task_type == "Code Optimization":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  st.info("Paste your Python code for optimization recommendations.")
31
  user_code = st.text_area("Paste your Python code", height=200)
32
  if st.button("Optimize Code"):
33
+ if user_code.strip() == "":
34
+ st.warning("Please paste valid Python code to optimize.")
35
+ else:
36
+ with st.spinner("Analyzing and optimizing..."):
37
+ try:
38
+ optimization_prompt = f"Optimize the following Python code:\n\n{user_code}"
39
+ output = nlp_pipeline(optimization_prompt)
40
+ optimized_code = output[0]["generated_text"]
41
+ st.subheader("Optimized Code")
42
+ st.code(optimized_code)
43
+ except Exception as e:
44
+ st.error(f"An error occurred while optimizing code: {e}")