SabaAnver commited on
Commit
37f3c70
·
verified ·
1 Parent(s): 660d978

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # Hugging Face API details
5
+ API_URL = "https://api-inference.huggingface.co/models/gpt2"
6
+ headers = {"Authorization": "Bearer YOUR_HF_API_TOKEN"} # <-- replace with your token
7
+
8
+ def query(payload):
9
+ response = requests.post(API_URL, headers=headers, json=payload)
10
+ return response.json()
11
+
12
+ st.title("✨ AI Quote Generator")
13
+ st.write("Generate inspiring quotes using Hugging Face + Streamlit")
14
+
15
+ topic = st.text_input("Enter a topic (e.g., happiness, love, success):", "")
16
+
17
+ if st.button("Generate Quote"):
18
+ if topic.strip() == "":
19
+ prompt = "Here is an inspiring quote:"
20
+ else:
21
+ prompt = f"Here is an inspiring quote about {topic}:"
22
+
23
+ output = query({"inputs": prompt, "max_length": 50, "num_return_sequences": 1})
24
+
25
+ if isinstance(output, list) and len(output) > 0:
26
+ st.success(output[0]['generated_text'])
27
+ else:
28
+ st.error("Something went wrong. Try again.")