-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram4.py
More file actions
52 lines (37 loc) · 1.57 KB
/
program4.py
File metadata and controls
52 lines (37 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
import google.generativeai as genai
def get_java_answer(user_question, gemini_api_key):
"""Get Java answer using Gemini with your required prompt."""
genai.configure(api_key=gemini_api_key)
model = genai.GenerativeModel('gemini-2.0-flash')
prompt = f"""
give the answer for the below questions in java language without comments
use only main function and not any other
add these and do not make any changes
Question: {user_question}
"""
response = model.generate_content(prompt)
return response.text
def create_java_app():
"""Create the Java Question Answering App."""
st.title("Java Program Generator (main() only)")
st.write("Enter any Java-related question. The system will generate a program with no comments.")
user_question = st.text_area("Enter your Java question:")
if st.button("Get Java Answer"):
if user_question.strip():
java_output = get_java_answer(user_question, st.session_state.gemini_api_key)
st.subheader("Generated Java Program")
st.code(java_output, language='java')
else:
st.warning("Please enter a question.")
def main():
st.sidebar.header("Configuration")
# INSERT YOUR KEY HERE (locally on your machine)
gemini_api_key = "AIzaSyCd55WdPJDuLJFFCJyjJDGYVBmWImbAaXw"
if gemini_api_key:
st.session_state.gemini_api_key = gemini_api_key
create_java_app()
else:
st.warning("Please enter your Gemini API Key")
if __name__ == "__main__":
main()