Spaces:
Build error
Build error
Update app.py
#2
by hamaadayubkhan - opened
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import fitz # PyMuPDF
|
|
| 4 |
from PIL import Image
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
|
|
|
| 7 |
|
| 8 |
# Load environment variables
|
| 9 |
load_dotenv()
|
|
@@ -44,23 +45,48 @@ if uploaded_file is not None:
|
|
| 44 |
# PDF SUMMARY
|
| 45 |
if selected_option == "📄 PDF SUMMARY":
|
| 46 |
st.write("### 📄 PDF SUMMARY")
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# BULLET SUMMARIZATION
|
| 52 |
elif selected_option == "📝 SUMMARIZE in BULLETS":
|
| 53 |
st.write("### 📝 SUMMARIZE in BULLETS")
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# TITLE AND HEADING GENERATION
|
| 59 |
elif selected_option == "📝 Title and Heading Generation":
|
| 60 |
st.write("### 📝 Title and Heading Generation")
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Display the response
|
| 66 |
st.write(st.session_state['response_text'])
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
+
import requests # For API calls
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
load_dotenv()
|
|
|
|
| 45 |
# PDF SUMMARY
|
| 46 |
if selected_option == "📄 PDF SUMMARY":
|
| 47 |
st.write("### 📄 PDF SUMMARY")
|
| 48 |
+
# API call to generate summary
|
| 49 |
+
response = requests.post(
|
| 50 |
+
"https://api.gemini.ai/summarize", # Replace with actual API endpoint
|
| 51 |
+
headers={"Authorization": f"Bearer {api_key}"},
|
| 52 |
+
json={"text": text_content, "length": "short"}
|
| 53 |
+
)
|
| 54 |
+
if response.status_code == 200:
|
| 55 |
+
st.session_state['response_text'] = response.json().get("summary", "Summary not available.")
|
| 56 |
+
else:
|
| 57 |
+
st.session_state['response_text'] = "Error: Unable to fetch summary."
|
| 58 |
+
|
| 59 |
# BULLET SUMMARIZATION
|
| 60 |
elif selected_option == "📝 SUMMARIZE in BULLETS":
|
| 61 |
st.write("### 📝 SUMMARIZE in BULLETS")
|
| 62 |
+
# API call to generate bullet points
|
| 63 |
+
response = requests.post(
|
| 64 |
+
"https://api.gemini.ai/summarize", # Replace with actual API endpoint
|
| 65 |
+
headers={"Authorization": f"Bearer {api_key}"},
|
| 66 |
+
json={"text": text_content, "format": "bullets"}
|
| 67 |
+
)
|
| 68 |
+
if response.status_code == 200:
|
| 69 |
+
st.session_state['response_text'] = "\n".join([f"- {point}" for point in response.json().get("bullets", ["No bullet points generated."])])
|
| 70 |
+
else:
|
| 71 |
+
st.session_state['response_text'] = "Error: Unable to fetch bullet points."
|
| 72 |
|
| 73 |
# TITLE AND HEADING GENERATION
|
| 74 |
elif selected_option == "📝 Title and Heading Generation":
|
| 75 |
st.write("### 📝 Title and Heading Generation")
|
| 76 |
+
# API call to generate titles and headings
|
| 77 |
+
response = requests.post(
|
| 78 |
+
"https://api.gemini.ai/generate", # Replace with actual API endpoint
|
| 79 |
+
headers={"Authorization": f"Bearer {api_key}"},
|
| 80 |
+
json={"text": text_content, "task": "title_generation"}
|
| 81 |
+
)
|
| 82 |
+
if response.status_code == 200:
|
| 83 |
+
titles = response.json().get("titles", [])
|
| 84 |
+
if titles:
|
| 85 |
+
st.session_state['response_text'] = "\n".join([f"{i+1}. {title}" for i, title in enumerate(titles)])
|
| 86 |
+
else:
|
| 87 |
+
st.session_state['response_text'] = "No title options generated."
|
| 88 |
+
else:
|
| 89 |
+
st.session_state['response_text'] = "Error: Unable to generate titles."
|
| 90 |
|
| 91 |
# Display the response
|
| 92 |
st.write(st.session_state['response_text'])
|