Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,26 @@ A magical AI that turns your boring long documents into... slightly less boring

---

## ~~🧙‍♂️ Abra-kadabra Setup (Azure Edition)~~
## 🧞‍♂️ OpenRouter Vibes (Free Magic Edition)

### ~~Numero uno - Azure Voodoo~~
1. ~~Get your student 🎓 email ready~~
2. ~~Go to [Azure Portal](https://portal.azure.com) (yes, the cloud place)~~
3. ~~Type `Language Service` like you're summoning a demon 🔮~~
### Numero uno - OpenRouter Shenanigans
1. Create an account at [OpenRouter](https://openrouter.ai/) — yes, it’s real, and no, it's not a Wi-Fi company.
2. Summon your **API key** from the shadows (or your [dashboard](https://openrouter.ai/account/keys)).
3. Choose a model — for this silly quest, I picked [**Mistral Small 3.1 24B (free)**](https://openrouter.ai/mistralai/mistral-small-3.1-24b-instruct:free) because it sounds fancy.
4. Pick the **Free plan** — because we’re broke but curious.
5. Browse other free models if you feel spicy 🌶️ — this one’s just a humble suggestion.

### ~~Numero dos - Resource Goofin'~~
~~Fill this bad boy like:~~
- ~~**Subscription**: "Azure for Students" (the free candy 🍭)~~
- ~~**Resource group**: `AI-Document-Summary` (or whatever)~~
- ~~**Region**: West Europe 🌍 (or pick your favorite)~~
- ~~**Name**: `kaka-doc-summary-ai` (mandatory "kaka" prefix)~~
- ~~**Pricing tier**: F0 (aka "please don't charge me" mode)~~
### Numero dos - The Sacred `.env` Scrolls 🧻

### ~~Numero tres - Secret Sauce 🕵️~~
~~After Azure stops judging your life choices:~~
1. ~~Go to "Keys and Endpoint" (sounds spy-ish)~~
2. ~~Create `.env` file in `config/` with:~~
Once you’ve tricked the system into trusting you, create a `.env` file inside `config/` (don’t ask, just do it).

It doesn't work, we used the wrong AI :( and Azure for Students doesn't let us access the OpenAI model.

We can only use a special model to summarize text files, but this Azure service just copies and pastes random sentences from our text.
```ini
AZURE_ENDPOINT='https://kaka-doc-summary-ai.cognitiveservices.azure.com/'
AZURE_API_KEY='your-magic-code-here'
API_VERSION='2023-04-01'
MAX_TOKENS=1000
API_KEY='your-api-key-here' # secret sauce
BASE_URL='https://openrouter.ai/api/v1' # the mothership
MODEL='mistralai/mistral-small-3.1-24b-instruct:free' # free = best flavor
```


## 🚀 Launch Protocol (for dummies)
### Option A: Docker Magic 🐳
```
Expand All @@ -60,4 +50,4 @@ streamlit run app/main.py # Do the thing
## 🎉 Special Thanks
- Azure for the free(ish) toys
- My cat for moral support 🐈
- Coffee ☕ (the real MVP)
- Coffee ☕ (the real MVP)
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
summarizzler = Summarizer(settings)
result = summarizzler.summarize(fileProcessor.get_content())
with st.spinner("Summarizing your doc...."):
time.sleep(5)
time.sleep(1)
st.success("Your summary is ready:")
st.markdown(result)

Expand Down
49 changes: 17 additions & 32 deletions app/src/summarizer.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import (
TextAnalyticsClient,
ExtractiveSummaryAction
)
from openai import OpenAI
from config.settings import Settings

class Summarizer:
def __init__(self, config: Settings):
self.endpoint = config.AZURE_ENDPOINT
self.key = config.AZURE_API_KEY
self.client = TextAnalyticsClient(
endpoint=self.endpoint,
credential=AzureKeyCredential(self.key)
self.api_key = config.API_KEY
self.base_url = config.BASE_URL
self.model = config.MODEL
self.client = OpenAI(
base_url=self.base_url,
api_key=self.api_key,
)

def summarize(self, text: str) -> str:
try:
actions = [
ExtractiveSummaryAction(
max_sentence_count=15,
order_by="Rank"
)
]

poller = self.client.begin_analyze_actions(
documents=[text],
actions=actions,
language="pl",
show_stats=True
completion = self.client.chat.completions.create(
model = self.model,
messages=[
{
"role": "user",
"content": f"Summarize this text:\n\n{text}"
}
]
)

results = list(poller.result())

summary_sentences = []
for result in results:
for action_result in result:
if not action_result.is_error:
summary_sentences.extend(
sentence.text for sentence in action_result.sentences
)
result = completion.choices[0].message.content

return " ".join(summary_sentences) if summary_sentences else "No summary generated"
return result

except Exception as e:
raise Exception(f"Summarization error: {str(e)}")
7 changes: 3 additions & 4 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
class Settings:
def __init__(self):
load_dotenv(dotenv_path=Path(".env"))
self.AZURE_ENDPOINT = os.getenv("AZURE_ENDPOINT", "").strip()
self.AZURE_API_KEY = os.getenv("AZURE_API_KEY", "")
self.API_VERSION = os.getenv("API_VERSION", "2023-05-15")
self.MAX_TOKENS = int(os.getenv("MAX_TOKENS", "1"))
self.API_KEY = os.getenv("API_KEY", "")
self.BASE_URL = os.getenv("BASE_URL", "")
self.MODEL = os.getenv("MODEL", "")

settings = Settings()
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ dotenv
requests
typing
pytest
azure-ai-textanalytics>=5.3.0
azure-core>=1.28.0
openai