diff --git a/README.md b/README.md index 4c187d0..278e353 100644 --- a/README.md +++ b/README.md @@ -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 ๐Ÿณ ``` @@ -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) \ No newline at end of file diff --git a/app/main.py b/app/main.py index 1e3d75e..30b8d1c 100644 --- a/app/main.py +++ b/app/main.py @@ -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) diff --git a/app/src/summarizer.py b/app/src/summarizer.py index a16e1db..a827912 100644 --- a/app/src/summarizer.py +++ b/app/src/summarizer.py @@ -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)}") \ No newline at end of file diff --git a/config/settings.py b/config/settings.py index 288efb1..2ca3aa8 100644 --- a/config/settings.py +++ b/config/settings.py @@ -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() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index eba99e0..b30634c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,4 @@ dotenv requests typing pytest -azure-ai-textanalytics>=5.3.0 -azure-core>=1.28.0 \ No newline at end of file +openai \ No newline at end of file