Files changed (1) hide show
  1. app.py +36 -10
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
- prompt = f"Provide a very short summary, no more than three to six sentences for this text:\n\n{text_content}\n\nSummary:"
48
- # Mock response for demo (replace with API call if available)
49
- st.session_state['response_text'] = "This is a concise summary of the uploaded PDF document."
50
-
 
 
 
 
 
 
 
51
  # BULLET SUMMARIZATION
52
  elif selected_option == "📝 SUMMARIZE in BULLETS":
53
  st.write("### 📝 SUMMARIZE in BULLETS")
54
- prompt = f"Provide a summary in four bullet points for this text:\n\n{text_content}"
55
- # Mock response for demo (replace with API call if available)
56
- st.session_state['response_text'] = "- Point 1\n- Point 2\n- Point 3\n- Point 4"
 
 
 
 
 
 
 
57
 
58
  # TITLE AND HEADING GENERATION
59
  elif selected_option == "📝 Title and Heading Generation":
60
  st.write("### 📝 Title and Heading Generation")
61
- prompt = f"Write a title for this text and provide five options:\n\n{text_content}"
62
- # Mock response for demo (replace with API call if available)
63
- st.session_state['response_text'] = "1. Title Option 1\n2. Title Option 2\n3. Title Option 3\n4. Title Option 4\n5. Title Option 5"
 
 
 
 
 
 
 
 
 
 
 
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'])