File size: 2,242 Bytes
d395b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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("<br>", 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("<br>", 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("<p style='text-align: center;'>Made with โค๏ธ using Streamlit & NVIDIA AI</p>", unsafe_allow_html=True)