import streamlit as st
from openai import OpenAI
import os
client = OpenAI(
base_url = "https://integrate.api.nvidia.com/v1",
api_key = os.environ.get("NVIDIA_API_KEY")
)
def ask_ai(prompt):
try:
completion = client.chat.completions.create(
model="meta/llama-3.2-3b-instruct",
messages=[{"role": "system", "content": "You are a professional writing assistant. Your task is to refine and improve the user's text, making it sound more professional, without altering its original meaning."},{"role": "user", "content": prompt}],
temperature=0.2,
top_p=0.7,
max_tokens=1024,
stream=True
)
response_container = st.empty() # Placeholder for dynamic updates
full_response = ""
for chunk in completion:
if hasattr(chunk.choices[0].delta, "content") and chunk.choices[0].delta.content:
full_response += chunk.choices[0].delta.content
response_container.write(full_response) # Display progressively
return full_response # Return the final response
except Exception as e:
st.error(f"Error: {e}")
return None
# Streamlit UI Design
st.set_page_config(page_title="Profeshify", page_icon="🛠️")
# Title & Description
st.markdown("## Profeshify 🛠️")
st.write("Enter your text below, and Profeshify will make it sound more polished for you.")
st.markdown("
", unsafe_allow_html=True)
st.markdown("#### 📝 Enter Your Text:")
txt_input = st.text_area("", height=150, placeholder="Type or paste your text here...")
# Action Button
st.markdown("
", unsafe_allow_html=True) # Spacing
col1, col2, col3 = st.columns([1, 2, 1]) # Center button
with col2:
refine_button = st.button("Profeshify It 🛠️", use_container_width=True)
# Processing Logic
if refine_button:
if txt_input.strip():
with st.spinner("🔍 Refining your text..."):
response = ask_ai(txt_input) # Get AI response
else:
st.warning("⚠️ Please enter some text to refine.")
# Footer
st.markdown("---")
st.markdown("
Made with ❤️ using Streamlit & NVIDIA AI
", unsafe_allow_html=True)