Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
# Initialize the OpenAI client
|
6 |
+
client = OpenAI(
|
7 |
+
base_url="https://api.studio.nebius.ai/v1/",
|
8 |
+
api_key=os.environ.get("NEBIUS_API_KEY") # Make sure to set this in Hugging Face Secrets
|
9 |
+
)
|
10 |
+
|
11 |
+
# Streamlit app title
|
12 |
+
st.title("AI Title Generator")
|
13 |
+
|
14 |
+
# Text Area Input Bar
|
15 |
+
user_input = st.text_area(
|
16 |
+
label="Enter a description for generating titles:",
|
17 |
+
placeholder="e.g., Man who went to jail for no reason"
|
18 |
+
)
|
19 |
+
|
20 |
+
# Generate Button
|
21 |
+
if st.button("Generate Titles"):
|
22 |
+
if user_input.strip():
|
23 |
+
try:
|
24 |
+
# API call to OpenAI
|
25 |
+
completion = client.chat.completions.create(
|
26 |
+
model="nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
|
27 |
+
messages=[
|
28 |
+
{"role": "system", "content": "Your task is to generate 3 very short titles based on the user input."},
|
29 |
+
{"role": "user", "content": user_input}
|
30 |
+
],
|
31 |
+
temperature=0.6,
|
32 |
+
maxTokens=512,
|
33 |
+
topP=0.9,
|
34 |
+
topK=50
|
35 |
+
)
|
36 |
+
|
37 |
+
# Extracting the generated titles
|
38 |
+
response_content = completion.choices[0].message["content"]
|
39 |
+
|
40 |
+
# Output Text Area
|
41 |
+
st.text_area(
|
42 |
+
label="Generated Titles:",
|
43 |
+
value=response_content,
|
44 |
+
height=200,
|
45 |
+
disabled=True
|
46 |
+
)
|
47 |
+
|
48 |
+
except Exception as e:
|
49 |
+
st.error(f"An error occurred: {e}")
|
50 |
+
else:
|
51 |
+
st.warning("Please provide input before clicking Generate.")
|
52 |
+
|