-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (59 loc) · 3.76 KB
/
main.py
File metadata and controls
73 lines (59 loc) · 3.76 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
import pandas as pd
import numpy as np
from utils import generate_ui, inference_gemini
st.set_page_config(
page_title="AutoUI",
page_icon=":robot:",
layout="wide",
)
st.title("AutoUI: Automated UI Generation")
st.write("This is a simple Streamlit app that generates UI components based on user input.")
if 'chat_input' not in st.session_state:
st.session_state['chat_input'] = ""
chat_input = st.text_input("Type your query here...")
if st.session_state['chat_input'] != "":
st.subheader(f"You: {st.session_state['chat_input']}")
if chat_input != st.session_state["chat_input"]:
st.session_state["chat_input"] = chat_input
with st.spinner("Generating UI..."):
prompt = f"""You are a helpful assistant.
You will be given a prompt and you will respond with a Python code snippet that generates a Streamlit UI based on the prompt.
The response should be a valid Python code snippet that can be executed in a Streamlit app.
Tool 1: Gemini API
You will have access to function for inferencing the Gemini API, if process user response from generated UI.
Use function `inference_gemini` and pass prompt to it. You don't need to import any libraries or modules.
The function will return a response as text.
Use the function only if it is of utmost importance.
Tool 2: Web Search
You will have access to function for google search and getting related articles. You can use this tool to get more information about the topic.
Use function `web_search` and pass query to it. You don't need to import any libraries or modules.
The function will return a response as text.
You can use this tool multiple times if needed.
The input query should be well written and should be related to the topic, that will directly be searched on Google to get the results.
Tool 3: Generate UI
You will have access to function for generating UI from the response of Gemini API. You can use this tool to generate UI more based on the response.
Use function `generate_ui` and pass valid streamlit python code to it. You don't need to import any libraries or modules.
The function will not return anything, it will just generate the UI based on the response.
You can use this tool multiple times if needed. You can use this tool to generate UI based on the user response.
Instructions:
1. Don't use any external libraries or modules.
2. Don't call above given tools unnecessarily.
3. Use st.spinner to show loading message while calling above given tools.
4. Use Gemini API for processing the web search results.
5. Think about what details you require to fulfill the user request. Ask these details from the user using the generated UI.
6. Use the generated UI to get the details from the user.
7. You must pass valid python streamlit UI to the `generate_ui` function, otherwise it will not work.
8. If you need to run the code, you can use `exec()` function to run the code pass globals() and locals() as arguments.
9. Clean code snippets generated by Gemini API and remove any unnecessary ```json, ```python or ``` tags.
OUPUT FORMAT:
```python
# Your Python code here
```
The prompt is: {st.session_state['chat_input']}"""
response = inference_gemini(prompt)
st.session_state['response'] = response
if 'response' in st.session_state:
with st.expander("Response from Gemini API"):
st.code(st.session_state['response'], language='python')
generate_ui(st.session_state['response'])