ritepaul commited on
Commit
10110b5
1 Parent(s): a1414d3

Add initial app and dependencies

Browse files
Files changed (3) hide show
  1. app.py +46 -0
  2. app.py:Zone.Identifier +0 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp.llama import Llama
2
+ import streamlit as st
3
+
4
+ # Load Model
5
+ try:
6
+ llm = Llama.from_pretrained(
7
+ repo_id="microsoft/Phi-3-mini-4k-instruct-gguf",
8
+ filename="*q4.gguf",
9
+ n_gpu_layers=0,
10
+ n_ctx=2048,
11
+ verbose=False
12
+ )
13
+ except Exception as e:
14
+ st.error(f"Error loading model: {e}")
15
+ llm = None
16
+
17
+ # Streamlit App
18
+ st.title("JUnit Test Case Generator")
19
+ st.write("Generate JUnit test cases for Java Method using Generative AI.")
20
+
21
+ # Text Area for Input
22
+ java_method = st.text_area("Enter Java Method", height=300)
23
+
24
+ # Generate Button
25
+ if st.button("Generate JUnit Test Cases"):
26
+ if llm:
27
+ if java_method.strip():
28
+ prompt = f"Write JUnit test cases for this function. Provide only the Java code without any explanation.\n\n{java_method}"
29
+ try:
30
+ # Generate test cases
31
+ response = llm.create_chat_completion(
32
+ messages=[
33
+ {"role": "user", "content": prompt}
34
+ ],
35
+ response_format={"type": "text"},
36
+ temperature=0.3,
37
+ top_k=30
38
+ )
39
+ output = response['choices'][0]['message']["content"]
40
+ st.text_area("Generated Test Cases", output, height=300)
41
+ except Exception as e:
42
+ st.error(f"Error generating test cases: {e}")
43
+ else:
44
+ st.warning("Please enter a valid Java Method.")
45
+ else:
46
+ st.error("Model not loaded. Please check the setup.")
app.py:Zone.Identifier ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit==1.40.1
2
+ llama-cpp-python==0.2.76