Spaces:
Sleeping
Sleeping
upload app file
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
client = OpenAI(
|
| 6 |
+
base_url = "https://integrate.api.nvidia.com/v1",
|
| 7 |
+
api_key = os.environ.get("NVIDIA_API_KEY")
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def ask_ai(prompt):
|
| 11 |
+
try:
|
| 12 |
+
completion = client.chat.completions.create(
|
| 13 |
+
model="meta/llama-3.2-3b-instruct",
|
| 14 |
+
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}],
|
| 15 |
+
temperature=0.2,
|
| 16 |
+
top_p=0.7,
|
| 17 |
+
max_tokens=1024,
|
| 18 |
+
stream=True
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
response_container = st.empty() # Placeholder for dynamic updates
|
| 22 |
+
full_response = ""
|
| 23 |
+
|
| 24 |
+
for chunk in completion:
|
| 25 |
+
if hasattr(chunk.choices[0].delta, "content") and chunk.choices[0].delta.content:
|
| 26 |
+
full_response += chunk.choices[0].delta.content
|
| 27 |
+
response_container.write(full_response) # Display progressively
|
| 28 |
+
|
| 29 |
+
return full_response # Return the final response
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
st.error(f"Error: {e}")
|
| 33 |
+
return None
|
| 34 |
+
|
| 35 |
+
# Streamlit UI Design
|
| 36 |
+
st.set_page_config(page_title="Profeshify", page_icon="🛠️")
|
| 37 |
+
|
| 38 |
+
# Title & Description
|
| 39 |
+
st.markdown("## Profeshify 🛠️")
|
| 40 |
+
st.write("Enter your text below, and Profeshify will make it sound more polished for you.")
|
| 41 |
+
|
| 42 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 43 |
+
|
| 44 |
+
st.markdown("#### 📝 Enter Your Text:")
|
| 45 |
+
txt_input = st.text_area("", height=150, placeholder="Type or paste your text here...")
|
| 46 |
+
|
| 47 |
+
# Action Button
|
| 48 |
+
st.markdown("<br>", unsafe_allow_html=True) # Spacing
|
| 49 |
+
col1, col2, col3 = st.columns([1, 2, 1]) # Center button
|
| 50 |
+
with col2:
|
| 51 |
+
refine_button = st.button("Profeshify It 🛠️", use_container_width=True)
|
| 52 |
+
|
| 53 |
+
# Processing Logic
|
| 54 |
+
if refine_button:
|
| 55 |
+
if txt_input.strip():
|
| 56 |
+
with st.spinner("🔍 Refining your text..."):
|
| 57 |
+
response = ask_ai(txt_input) # Get AI response
|
| 58 |
+
else:
|
| 59 |
+
st.warning("⚠️ Please enter some text to refine.")
|
| 60 |
+
|
| 61 |
+
# Footer
|
| 62 |
+
st.markdown("---")
|
| 63 |
+
st.markdown("<p style='text-align: center;'>Made with ❤️ using Streamlit & NVIDIA AI</p>", unsafe_allow_html=True)
|