Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,40 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
# Load the model
|
| 4 |
-
model_interface = gr.load("models/google/gemma-2-2b-it")
|
| 5 |
-
|
| 6 |
-
# Create a Gradio interface with custom title and logo
|
| 7 |
def main():
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
-
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_ollama import OllamaLLM
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def main():
|
| 6 |
+
# Set up the page
|
| 7 |
+
st.set_page_config(page_title="Nudge Generator - Gemma 2b", page_icon="orYx logo.png", layout="wide")
|
| 8 |
+
|
| 9 |
+
# Title and logo
|
| 10 |
+
col1, col2 = st.columns([3, 1])
|
| 11 |
+
with col1:
|
| 12 |
+
st.title("Nudge Generator - Gemma 2b")
|
| 13 |
+
with col2:
|
| 14 |
+
st.image("orYx logo.png", use_column_width=True)
|
| 15 |
+
|
| 16 |
+
# Chat interface
|
| 17 |
+
st.markdown("---")
|
| 18 |
+
st.header("Chat Interface")
|
| 19 |
+
|
| 20 |
+
# Input for user-provided data
|
| 21 |
+
prompt = st.text_area("Enter the prompt here:")
|
| 22 |
+
|
| 23 |
+
# Initialize the models
|
| 24 |
+
gemma_model = OllamaLLM(model='gemma:2b')
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
|
| 26 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b-it")
|
| 27 |
|
| 28 |
+
# Button to generate the nudge
|
| 29 |
+
if st.button("Generate Nudge"):
|
| 30 |
+
if S_boss.strip():
|
| 31 |
+
with st.spinner("Generating nudges..."):
|
| 32 |
+
# Generate the response using Ollama LLM
|
| 33 |
+
response = gemma_model.invoke(input=f"I want you to analyze the {prompt}. Which contains top 3 strengths or weaknesses of a person being assessed. You will generate nudges for improving upon these strengths or fixing upon these weaknesses. If you don't find any data, just respond as - No data available.")
|
| 34 |
+
st.success("Nudges generated successfully!")
|
| 35 |
+
st.text_area("Generated Nudges:", response, height=200)
|
| 36 |
+
else:
|
| 37 |
+
st.warning("Please enter data to generate nudges.")
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
+
main()
|