<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CodeAIGo on Medium]]></title>
        <description><![CDATA[Stories by CodeAIGo on Medium]]></description>
        <link>https://medium.com/@codeaigo?source=rss-7d96c3963537------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ySdCQMm4EraEFdSUhzsT1Q.png</url>
            <title>Stories by CodeAIGo on Medium</title>
            <link>https://medium.com/@codeaigo?source=rss-7d96c3963537------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:10:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codeaigo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Voice Assistant with Streamlit and OpenAI ]]></title>
            <link>https://medium.com/@codeaigo/building-a-voice-assistant-with-streamlit-and-openai-48439d640f08?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/48439d640f08</guid>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 01:05:45 GMT</pubDate>
            <atom:updated>2025-01-28T01:05:45.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DU6gp748Is_11CnHhDHKJQ.png" /></figure><p>Voice assistants have become an integral part of modern technology. From answering questions to automating tasks, they simplify our lives. In this tutorial, I’ll walk you through how I built a simple yet powerful Voice Assistant using <strong>Streamlit</strong>, <strong>OpenAI’s APIs</strong>, and some other Python magic!</p><h3>Key Features of the App</h3><ul><li><strong>Voice Input</strong>: Speak directly into the app, no need to type!</li><li><strong>Speech-to-Text</strong>: Your spoken words are transcribed using OpenAI’s <strong>Whisper</strong> model.</li><li><strong>AI Responses</strong>: The app responds intelligently using OpenAI’s <strong>ChatGPT</strong>.</li><li><strong>Text-to-Speech</strong>: The AI’s response is converted to audio for a complete voice interaction experience.</li></ul><h3>Technologies Used</h3><ol><li><strong>Streamlit</strong>: To create an interactive web app.</li><li><strong>OpenAI</strong>: For transcription, AI-generated responses, and text-to-speech conversion.</li><li><strong>audio-recorder-streamlit</strong>: For recording audio directly from the browser.</li><li><strong>Python</strong>: For integrating everything seamlessly.</li></ol><p>Here’s what the app looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DU6gp748Is_11CnHhDHKJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0ctYNXSEoQA9OvlD0qZ9g.png" /></figure><h3>Code Overview</h3><p>Here’s a quick breakdown of the key code sections:</p><h4>Audio Recording</h4><p>We used the audio-recorder-streamlit package for simple audio recording:</p><pre>recorded_audio = audio_recorder()</pre><h4>Speech-to-Text</h4><p>OpenAI’s Whisper model handles audio transcription:</p><pre>def transcribe_audio(client, audio_path):  <br>    with open(audio_path, &quot;rb&quot;) as audio_file:  <br>        transcript = client.audio.transcriptions.create(model=&quot;whisper-1&quot;, file=audio_file)  <br>        return transcript.text</pre><h4>AI Response</h4><p>Using ChatGPT for generating AI responses:</p><pre>def fetch_ai_response(client, input_text):  <br>    messages = [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: input_text}]  <br>    response = client.chat.completions.create(model=&quot;gpt-3.5-turbo&quot;, messages=messages)  <br>    return response.choices[0].message.content</pre><h3>Final Thoughts</h3><p>Building this app was a rewarding experience. It demonstrates how accessible AI tools like OpenAI’s APIs and user-friendly frameworks like Streamlit make it possible to create impactful projects.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48439d640f08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Aid Assistant: A Voice-Driven Medical Guide with AI and Video Resources]]></title>
            <link>https://medium.com/@codeaigo/first-aid-assistant-a-voice-driven-medical-guide-with-ai-and-video-resources-bf23a25e5a87?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf23a25e5a87</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[first-aid]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Wed, 08 Jan 2025 15:15:30 GMT</pubDate>
            <atom:updated>2025-01-08T15:15:30.980Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yx4-Y1ASRhRvX6EqFh5fBA.png" /><figcaption>First Aid Assistant</figcaption></figure><p>In emergency situations, access to accurate and timely first aid information can make all the difference. However, in the stress of an emergency, it’s not always easy to search for answers or remember the right steps. That’s where the <strong>First Aid Assistant</strong> comes in an innovative, AI-powered application designed to provide immediate medical guidance based on user input. By combining voice recognition, generative AI, and YouTube video resources, this assistant offers a comprehensive and user-friendly solution for first aid assistance.</p><h3>Key Features:</h3><ol><li><strong>Voice Interaction for Seamless Communication</strong>:<br>One of the standout features of the <strong>First Aid Assistant</strong> is its voice-based interaction. Instead of typing out medical queries, users can speak directly to the assistant. The application uses the <strong>SpeechRecognition</strong> library to transcribe audio into text. This feature allows users to interact with the assistant hands-free, making it especially useful in urgent situations when every second counts.</li><li><strong>AI-Powered Medical Advice</strong>:<br> At the core of the application is <strong>Google’s Generative AI (gemini-1.5-flash)</strong>, which processes the transcribed text and provides real-time, actionable first aid advice. The assistant is designed to offer clear, concise instructions for addressing a wide range of medical emergencies. Whether it’s a burn, a cut, a heart attack, or a choking incident, the assistant will deliver easy-to-follow steps to guide the user through the situation. The system is trained to understand natural language, so users can ask questions in a conversational manner and receive immediate, relevant advice.</li><li><strong>YouTube Video Suggestions for Visual Guidance</strong>:<br> In addition to providing text-based advice, the assistant takes it a step further by generating a related YouTube search query based on the medical scenario. For example, if the assistant provides first aid steps for CPR, it will automatically suggest a YouTube search for videos on performing CPR. The application then fetches and displays these videos right on the interface, allowing users to watch real-time demonstrations of the necessary actions. This visual support helps users better understand the steps they need to take, reducing confusion and ensuring they feel confident in their ability to assist.</li><li><strong>Intuitive User Experience</strong>:<br> Built with <strong>Streamlit</strong>, the application provides an intuitive, interactive interface. The design is clean and user-friendly, ensuring that users can easily navigate through the different features of the app. From speaking to the assistant to watching YouTube videos, everything is streamlined for a smooth and stress-free experience. The voice input is immediate, and the assistant’s responses are quick and informative.</li><li><strong>Comprehensive Assistance</strong>:<br> The <strong>First Aid Assistant</strong> isn’t just about providing advice it is a comprehensive tool for handling emergency situations. The combination of voice input, AI-powered responses, and video resources makes it a powerful solution for people looking for accurate, actionable guidance. Whether you’re at home, in the workplace, or out in a public space, you can trust the assistant to provide reliable support when you need it most.</li></ol><h3>How It Works:</h3><ol><li><strong>Voice Input</strong>: Users can speak directly into the application, describing the medical emergency or asking for advice. The application records the audio and uses <strong>SpeechRecognition</strong> to transcribe it into text.</li><li><strong>AI-Generated Response</strong>: The transcribed text is sent to <strong>Google’s Generative AI</strong> for processing. The AI analyzes the input and generates a concise first aid response that includes clear, actionable steps. These instructions help guide the user through the emergency, ensuring they know exactly what to do.</li><li><strong>YouTube Video Suggestions</strong>: Based on the AI-generated medical advice, the assistant formulates a YouTube search query for related instructional videos. For example, if the user asks about how to treat a burn, the assistant might suggest searching for “how to treat a second-degree burn” on YouTube. It then fetches the most relevant video links and displays them in the sidebar. This feature helps users watch real-time tutorials on first aid procedures, offering an extra layer of support.</li><li><strong>Instant Access</strong>: The entire process happens in real time, providing users with quick answers to their pressing medical questions. Whether it’s a severe injury or a minor ailment, the assistant ensures users are never left in the dark.</li></ol><h3>Why It Matters:</h3><p>In emergencies, having immediate access to reliable medical advice is critical. The <strong>First Aid Assistant</strong> provides users with an easy, accessible, and effective solution for dealing with medical situations. By combining the power of generative AI with the convenience of voice interaction and video resources, the application empowers individuals to act quickly and confidently in emergency situations.</p><p>For those who may not have access to professional help immediately, or those who need a second opinion in critical moments, this assistant can be a lifesaver. The combination of AI-driven advice and video demonstrations increases the likelihood of positive outcomes during emergencies, ensuring that users are well-prepared to deal with a variety of medical issues.</p><h3>Real-World Impact:</h3><p>The <strong>First Aid Assistant</strong> can be used in a variety of settings whether at home, in a workplace, or out in public. It’s designed for anyone, from parents looking to learn how to treat a child’s injury to office workers handling a colleague’s medical emergency. By making first aid more accessible and understandable, the application can help reduce anxiety and confusion during critical situations, ultimately saving lives and promoting safety.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf23a25e5a87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an AI-Powered Symptom Checker and Medical Assistant with GPT Models]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codeaigo/building-an-ai-powered-symptom-checker-and-medical-assistant-with-gpt-models-dd6d4b068d8d?source=rss-7d96c3963537------2"><img src="https://cdn-images-1.medium.com/max/680/1*59uClVpzSPQqdn55Jn2fZA.png" width="680"></a></p><p class="medium-feed-snippet">Revolutionizing Medical Assistance with AI-Powered Symptom Checker</p><p class="medium-feed-link"><a href="https://medium.com/@codeaigo/building-an-ai-powered-symptom-checker-and-medical-assistant-with-gpt-models-dd6d4b068d8d?source=rss-7d96c3963537------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codeaigo/building-an-ai-powered-symptom-checker-and-medical-assistant-with-gpt-models-dd6d4b068d8d?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd6d4b068d8d</guid>
            <category><![CDATA[doctors]]></category>
            <category><![CDATA[ai-assistant]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Wed, 08 Jan 2025 02:35:39 GMT</pubDate>
            <atom:updated>2025-01-08T02:35:39.465Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Elevating Tic-Tac-Toe: Playing Against an AI Trained with Q-Learning]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@codeaigo/elevating-tic-tac-toe-playing-against-an-ai-trained-with-q-learning-ea9b8add51c4?source=rss-7d96c3963537------2"><img src="https://cdn-images-1.medium.com/max/969/1*mgJJmaahgo5yE832o8ew6w.png" width="969"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/@codeaigo/elevating-tic-tac-toe-playing-against-an-ai-trained-with-q-learning-ea9b8add51c4?source=rss-7d96c3963537------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@codeaigo/elevating-tic-tac-toe-playing-against-an-ai-trained-with-q-learning-ea9b8add51c4?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea9b8add51c4</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[tic-tac-toe]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[q-learning]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Wed, 08 Jan 2025 02:09:14 GMT</pubDate>
            <atom:updated>2025-01-08T02:09:14.071Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Car Plate Detection and OCR Using YOLO and Google Gemini API]]></title>
            <link>https://medium.com/@codeaigo/car-plate-detection-and-ocr-using-yolo-9630c60a8ed3?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/9630c60a8ed3</guid>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Mon, 06 Jan 2025 00:38:42 GMT</pubDate>
            <atom:updated>2025-01-06T00:39:20.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9skT1QQdcHWMOo0xmqOing.png" /></figure><h3>Introduction</h3><p>License plate recognition is a crucial technology in various fields, including traffic monitoring, toll collection, and security enforcement. This article explores how to build an end-to-end car plate detection and OCR (Optical Character Recognition) system using <strong>YOLO (You Only Look Once)</strong> for object detection and <strong>Google Gemini API</strong> for text extraction. The project is implemented using <strong>Streamlit</strong>, a Python-based framework for interactive applications.</p><h3>How It Works</h3><p>Our system follows these key steps:</p><ol><li><strong>Image Upload</strong>: Users upload an image containing one or more vehicles.</li><li><strong>License Plate Detection</strong>: The YOLO model detects license plates and draws bounding boxes.</li><li><strong>Plate Cropping</strong>: The detected plates are extracted from the image.</li><li><strong>OCR Processing</strong>: The extracted plate images are processed through the <strong>Google Gemini API</strong> to extract text.</li><li><strong>Result Display</strong>: The recognized license plate numbers are displayed on the image.</li></ol><h3>Setting Up the Environment</h3><p>Before running the code, install the required libraries:</p><pre>pip install streamlit opencv-python matplotlib ultralytics pillow google-generativeai numpy</pre><p>We also need a trained <strong>YOLO model</strong> (best.pt) for license plate detection. You can train a custom model or use a pre-trained one.</p><h3>Code Implementation</h3><p>Below is the complete Python script:</p><pre>import streamlit as st<br>import cv2<br>import matplotlib.pyplot as plt<br>from ultralytics import YOLO<br>from PIL import Image<br>import io<br>import os<br>import google.generativeai as genai<br>import numpy as np<br>import time<br><br># Set Google API Key<br>os.environ[&quot;GOOGLE_API_KEY&quot;] = &quot;YOUR_GOOGLE_API_KEY&quot;<br>genai.configure(api_key=os.getenv(&quot;GOOGLE_API_KEY&quot;))<br><br># Load the YOLO model<br>model = YOLO(&#39;path_to_your_model/best.pt&#39;)<br><br># Function to crop license plates<br>def crop_licence_plate(bbox, ori_img):<br>    x1, y1, x2, y2 = map(int, bbox)<br>    return ori_img[y1:y2, x1:x2]<br><br># Predict bounding boxes<br>def predict_bounding_box(img):<br>    bboxes = []<br>    results = model.predict(img)<br>    for res in results:<br>        for box in res.boxes:<br>            b = box.xyxy.tolist()[0]<br>            bboxes.append([int(b[0]), int(b[1]), int(b[2]), int(b[3])])<br>    return bboxes<br><br># Function to process image and send to API<br>def process_and_send_to_api(cropped_img, question):<br>    pil_image = Image.fromarray(cv2.cvtColor(cropped_img, cv2.COLOR_BGR2RGB))<br>    buffer = io.BytesIO()<br>    pil_image.save(buffer, format=&quot;JPEG&quot;)<br>    image_part = {&quot;mime_type&quot;: &quot;image/jpeg&quot;, &quot;data&quot;: buffer.getvalue()}<br>    response = genai.GenerativeModel(&quot;gemini-1.5-flash&quot;).generate_content([question, image_part])<br>    return response.text<br><br># Streamlit App<br>st.title(&quot;Car Plate Detection and OCR&quot;)<br>st.subheader(&quot;Upload an image, detect car plates, and extract their text&quot;)<br><br>uploaded_file = st.file_uploader(&quot;Choose an image&quot;, type=[&quot;jpg&quot;, &quot;jpeg&quot;, &quot;png&quot;])<br><br>if uploaded_file:<br>    file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)<br>    img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)<br>    st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), caption=&quot;Uploaded Image&quot;, use_column_width=True)<br>    <br>    bboxes = predict_bounding_box(img)<br>    for i, bbox in enumerate(bboxes):<br>        cropped_plate = crop_licence_plate(bbox, img)<br>        first_response = process_and_send_to_api(cropped_plate, &quot;Is this image a car plate? (Yes/No)&quot;)<br>        <br>        if &quot;yes&quot; in first_response.lower():<br>            extracted_text = process_and_send_to_api(cropped_plate, &quot;Extract the text on this license plate.&quot;)<br>            st.image(cv2.cvtColor(cropped_plate, cv2.COLOR_BGR2RGB), caption=f&quot;Cropped Plate {i + 1}&quot;, use_column_width=True)<br>            st.write(f&quot;Extracted Text: {extracted_text}&quot;)</pre><h3>Results and Applications</h3><p>Once the image is uploaded, the model detects the license plate and extracts its text using <strong>Google Gemini API</strong>. The recognized plate text can be used for:</p><ul><li><strong>Vehicle Identification</strong></li><li><strong>Automated Parking Systems</strong></li><li><strong>Traffic Monitoring</strong></li><li><strong>Security &amp; Surveillance</strong></li></ul><h3>Conclusion</h3><p>This project demonstrates the power of AI in <strong>automated license plate recognition</strong> by combining <strong>YOLO for object detection</strong> and <strong>Google Gemini API for OCR</strong>. The Streamlit interface makes the application <strong>user-friendly and interactive</strong>.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding, and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9630c60a8ed3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Style Transfer with VGG19: Transforming Images Using Deep Learning]]></title>
            <link>https://medium.com/@codeaigo/neural-style-transfer-with-vgg19-transforming-images-using-deep-learning-83ad3a7c9859?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/83ad3a7c9859</guid>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 21:14:24 GMT</pubDate>
            <atom:updated>2024-11-28T21:14:24.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxOFlC3PI6EWMQAEfg3I0w.png" /></figure><p>In this project, I applied <strong>Neural Style Transfer (NST)</strong> to combine a content image and a style image using deep learning techniques. This method leverages the power of convolutional neural networks (CNNs), specifically the pre-trained <strong>VGG19 model</strong>, to extract the content and style of images and merge them into a new, generated image that retains the content of one image while adopting the artistic style of another.</p><h3>How Neural Style Transfer Works</h3><p>NST is a technique that allows us to blend two images: a <strong>content image</strong> and a <strong>style image</strong>. The result is a new image that:</p><ul><li><strong>Retains the content</strong> of the content image (e.g., objects, layout).</li><li><strong>Imitates the artistic style</strong> of the style image (e.g., color patterns, textures).</li></ul><h3>Key Concepts</h3><ul><li><strong>Content Representation:</strong> The content of the image is captured through specific layers in a neural network.</li><li><strong>Style Representation:</strong> The style of the image is represented using the <strong>Gram matrix</strong>, which captures the correlations between different features in the image.</li></ul><p>By training the model to minimize the difference between these representations in the content and style images, the model gradually produces the final generated image.</p><h3>Model Setup</h3><p>To implement this, I used the <strong>VGG19 model</strong> pre-trained on ImageNet. This model has been fine-tuned for image recognition and is particularly well-suited for feature extraction.</p><p>The VGG19 model’s architecture consists of multiple layers, and for NST, I used both content and style layers to compute the differences between the images. I worked with 5 layers for style and 1 layer for content.</p><h4>VGG19 Model Layers Used:</h4><ul><li><strong>Style Layers:</strong> block1_conv1, block2_conv1, block3_conv1, block4_conv1, block5_conv1</li><li><strong>Content Layer:</strong> block5_conv4</li></ul><pre>vgg = tf.keras.applications.VGG19(include_top=False, input_shape=(img_size, img_size, 3), weights=&#39;pretrained-model/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5&#39;)</pre><h3>Image Preprocessing</h3><p>Both the content and style images are resized to a uniform size of <strong>400x400</strong> pixels. The preprocessing ensures that both images are compatible with the model’s input size.</p><h3>Training the Model</h3><p>I initialized a <strong>generated image</strong> with random noise and iteratively refined it to minimize the loss functions for content and style.</p><p>The training process involves the following loss functions:</p><ul><li><strong>Content loss</strong> measures the difference between the content representation of the content image and the generated image.</li><li><strong>Style loss</strong> calculates the difference between the style representations of the style image and the generated image.</li></ul><h4>Training Configuration:</h4><ul><li><strong>Learning rate:</strong> 0.001</li><li><strong>Epochs:</strong> 20,000</li></ul><p>This high number of epochs ensures that the model will converge and produce a stable result after numerous iterations. After 20,000 epochs, the result stabilizes, producing a visually satisfying transformation.</p><h3>Visual Results</h3><p>After training for <strong>20,000 epochs</strong>, the generated image reaches a state where the content and style are successfully blended.</p><p>After 250 epochs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*W_WVdBZnORjwjZ5u24yIbA.png" /></figure><p>After 10,000 epochs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*xfCSB-IN_u5zBdoFcbqN2w.png" /></figure><p>After 20,000 epochs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*16AMv3-JisKbHTTzdEAMGg.png" /></figure><h3>Conclusion</h3><p>Neural Style Transfer is a powerful technique that can create visually stunning transformations by combining the content of one image with the style of another. The process involves using a pre-trained VGG19 model to extract features, which are then used to compute losses for both content and style. After 20,000 epochs, the result stabilizes and produces an image that is both visually appealing and faithful to the content and style of the original images.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding, and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83ad3a7c9859" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Medium Article: Build a Q&A App with Streamlit and LangChain for Website Content]]></title>
            <link>https://medium.com/@codeaigo/medium-article-build-a-q-a-app-with-streamlit-and-langchain-for-website-content-48f1bf62550a?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/48f1bf62550a</guid>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 20:54:01 GMT</pubDate>
            <atom:updated>2024-11-28T20:54:01.862Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s article, we will walk through the creation of an app that allows users to input a website URL and ask questions based on its content. The app leverages <strong>Streamlit</strong> for the front-end, <strong>LangChain</strong> for document loading and language model integration, and <strong>Hugging Face</strong> for the NLP model powering the Q&amp;A functionality. Let’s dive into how this app works and explore the different components.</p><h3>Introduction</h3><p>Imagine you stumble upon an informative article or research paper online and you want to quickly find answers to specific questions based on its content. Our Q&amp;A app does just that by processing the content of any webpage and allowing users to interactively ask questions, get relevant answers, and save time!</p><p>This article will guide you through the entire process of building this app step-by-step, from setting up the environment to implementing the logic for the question-answering functionality.</p><h3>App Overview</h3><p>The app is designed to:</p><ul><li>Take a URL input from the user.</li><li>Process the content of the URL using <strong>LangChain</strong> to load, split, and embed the document.</li><li>Use a <strong>Hugging Face model</strong> to generate answers based on the content of the webpage.</li><li>Return the answer to the user in real-time using <strong>Streamlit’s</strong> interface.</li></ul><h3>How It Works</h3><ol><li><strong>User Input:</strong> The user provides a URL of the website they want to explore.</li><li><strong>Web Scraping &amp; Document Loading:</strong> The app loads the document content using <strong>LangChain’s WebBaseLoader</strong>.</li><li><strong>Document Splitting:</strong> The document is split into chunks using <strong>CharacterTextSplitter</strong> to make it easier to process.</li><li><strong>Text Embedding:</strong> The app uses <strong>SentenceTransformerEmbeddings</strong> to generate embeddings for the content.</li><li><strong>Vector Search:</strong> These embeddings are stored in <strong>Chroma</strong>, a vector database, for efficient retrieval.</li><li><strong>Question Answering:</strong> The user can ask questions, which are processed by the <strong>Hugging Face</strong> model to generate relevant answers based on the document content.</li><li><strong>Response Display:</strong> Finally, the answer is displayed on the Streamlit interface.</li></ol><p>Below is a quick breakdown of the key sections of the code:</p><h4>Model Initialization</h4><p>We load a pre-trained model from Hugging Face to answer questions:</p><pre>repo_id = &quot;google/gemma-2b-it&quot;<br>llm = HuggingFaceEndpoint(<br>    repo_id=repo_id, max_length=1024, temperature=0.1<br>)</pre><h4>Web Scraping &amp; Text Processing</h4><p>We load the webpage using WebBaseLoader and split the content into manageable chunks:</p><pre>loader = WebBaseLoader(url)<br>data = loader.load()<br>text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)<br>docs = text_splitter.split_documents(data)</pre><h4>Text Embeddings &amp; Vector Search</h4><p>Next, we embed the content and store it in <strong>Chroma</strong> for fast retrieval:</p><pre>embedding_function = SentenceTransformerEmbeddings(model_name=&quot;all-MiniLM-L6-v2&quot;)<br>db = Chroma.from_documents(docs, embedding_function)<br>retriever = db.as_retriever(search_type=&quot;mmr&quot;, search_kwargs={&#39;k&#39;: 4, &#39;fetch_k&#39;: 20})</pre><h4>Question Answering</h4><p>Finally, the user’s question is passed through the retrieval system, and the app generates an answer using the model:</p><pre>response = rag_chain.invoke(question)<br>st.write(f&quot;Answer: {response}&quot;)</pre><h4>User Interface (UI)</h4><p>The app’s UI is built using <strong>Streamlit</strong>, making it easy to set up a front-end without worrying too much about design. The user simply enters a website URL and asks a question based on that content.</p><pre>st.title(&quot;Ask Questions Based on Website Content&quot;)<br>url = st.text_input(&quot;Enter the URL of the website:&quot;)<br>question = st.text_input(&quot;Ask a question based on the website content:&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*mMmeN07fAufA7NNc2ixkZA.png" /></figure><h3>Conclusion</h3><p>With this app, users can interact with website content and get answers to any question they might have. Whether you’re analyzing research papers, reading articles, or exploring any kind of web content, this app can help you retrieve relevant information quickly and efficiently. By integrating <strong>Hugging Face</strong>, <strong>LangChain</strong>, and <strong>Streamlit</strong>, we were able to build a powerful, easy-to-use Q&amp;A tool for any website.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding, and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48f1bf62550a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Multilingual Summarization App with Streamlit and LangChain]]></title>
            <link>https://medium.com/@codeaigo/creating-a-multilingual-summarization-app-with-streamlit-and-langchain-6361756d085e?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/6361756d085e</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[summarization]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Sun, 27 Oct 2024 21:09:39 GMT</pubDate>
            <atom:updated>2024-10-27T21:09:39.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xm6z1U9LVfd3VoeAjEM2EQ.png" /></figure><p>In today’s fast-paced digital world, we often don’t have the time to sift through lengthy content, whether it’s a PDF, a YouTube video, or an article on a website. This article walks you through building a multilingual content summarization app using Streamlit, LangChain, and OpenAI’s language models to tackle this problem.</p><h3>Why Summarization?</h3><p>With so much information available, we need efficient ways to distill key insights without spending hours reading or watching. Summarization apps help us focus on what matters by extracting essential points quickly. This app does exactly that by summarizing PDFs, YouTube transcripts, and online articles in a single, user-friendly interface.</p><h3>Technology Stack</h3><ol><li><strong>Streamlit</strong>: An easy-to-use Python framework for building data-driven web applications.</li><li><strong>LangChain</strong>: Provides customizable workflows for handling complex language processing tasks.</li><li><strong>OpenAI’s GPT Models</strong>: These models generate high-quality summaries from the extracted content.</li><li><strong>PyPDF2 &amp; LangDetect</strong>: Used for reading PDF files and detecting content language for better multilingual support.</li></ol><h3>Step 1: Setting Up the Interface with Streamlit</h3><p>The app interface in Streamlit is straightforward: users enter their API key in the sidebar, which lets the app authenticate with OpenAI’s API. Additionally, they can choose the content source PDF, YouTube, or URL to summarize.</p><pre>import streamlit as st<br><br>st.set_page_config(page_title=&quot;Summarize Content&quot;, page_icon=&quot;📘&quot;)<br>st.title(&quot;Summarize Content App&quot;)<br><br># Sidebar for API key<br>api_key = st.sidebar.text_input(&quot;Enter your ChatGPT API key&quot;, type=&quot;password&quot;)</pre><p>With Streamlit’s set_page_config, the app title and icon are set to create a welcoming interface. The sidebar API key entry provides secure integration with OpenAI’s services.</p><h3>Step 2: Reading PDFs and Summarizing Content</h3><p>For PDF summarization, we first read and extract text from the document using PyPDF2, which can handle multi-page PDFs. The app then processes this content using LangChain’s language model chain.</p><pre>from PyPDF2 import PdfReader<br><br>def read_pdf(uploaded_file):<br>    text = &#39;&#39;<br>    pdf_reader = PdfReader(uploaded_file)<br>    for page in pdf_reader.pages:<br>        text += page.extract_text()<br>    return text</pre><p>This function loops through each page in a PDF, extracting text and assembling it into a single string. Once the text is ready, it can be sent to the summarization chain.</p><h3>Step 3: Summarizing YouTube Transcripts</h3><p>Using LangChain’s YoutubeLoader, the app can fetch YouTube transcripts in various languages. This allows users to get summaries from YouTube videos, even if the original language isn’t English.</p><pre>from langchain_community.document_loaders import YoutubeLoader<br><br>def summarize_youtube_transcript(youtube_url, llm, translate_to_english):<br>    loader = YoutubeLoader.from_youtube_url(https://medium.com/youtube_url,%20translation=&quot;en&quot;%20if%20translate_to_english%20else%20None)<br>    result = loader.load()<br>    # Process and summarize the transcript<br>    ...</pre><p>This function uses YoutubeLoader to retrieve transcripts and translates them if needed, making it easy to access content in multiple languages.</p><h3>Step 4: Summarizing Web Content</h3><p>To handle content from URLs, the app utilizes LangChain’s SeleniumURLLoader. This tool extracts web content and prepares it for summarization.</p><pre>from langchain_community.document_loaders import SeleniumURLLoader<br><br>def summarize_url_content(url, llm):<br>    loader = SeleniumURLLoader(urls=[url])<br>    data = loader.load()<br>    # Summarize text content from URL<br>    ...</pre><p>This functionality expands the app’s reach, enabling it to summarize a wide array of online content, such as articles, research papers, and more.</p><h3>Step 5: Bringing It All Together in Streamlit</h3><p>Users select their content type PDF, YouTube, or URL and input the relevant details. The app processes this input, generates a summary, and displays the results.</p><pre>option = st.selectbox(&quot;Select option&quot;, [&quot;Upload PDF file&quot;, &quot;YouTube Link&quot;, &quot;URL&quot;])<br><br>if option == &quot;Upload PDF file&quot;:<br>    pdf_file = st.file_uploader(&quot;Upload PDF file&quot;, type=[&quot;pdf&quot;])<br>    if pdf_file and st.button(&quot;Summarize&quot;):<br>        # Initialize OpenAI model and summarize<br>        summary = summarize_text(read_pdf(pdf_file), llm)<br>        st.write(summary)<br>elif option == &quot;YouTube Link&quot;:<br>    youtube_link = st.text_input(&quot;Enter YouTube video link&quot;)<br>    if st.button(&quot;Summarize&quot;):<br>        summary = summarize_youtube_transcript(youtube_link, llm, translate_to_english)<br>        st.write(summary)<br>else:<br>    url = st.text_input(&quot;Enter URL&quot;)<br>    if st.button(&quot;Summarize&quot;):<br>        summary = summarize_url_content(url, llm)<br>        st.write(summary)</pre><p>Each user selection is routed to the relevant summarization function. This code highlights Streamlit’s flexibility in creating intuitive, interactive user experiences across different content formats.</p><h3>Conclusion</h3><p>By combining Streamlit, LangChain, and OpenAI, we’ve built a multilingual summarization app that handles content from diverse sources. This app offers a highly accessible solution for users who need quick summaries of documents, videos, or online articles. With some further customization, this app could also support additional languages, custom summary styles, or even keyword extraction, making it an even more powerful tool for today’s content-heavy world.</p><p>In sum, this app streamlines content consumption, saving users time and providing insights at a glance. It’s an example of how technology can simplify and enhance our engagement with digital information.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6361756d085e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Repository Insight Finder: A Streamlit Application for Discovering AI Projects]]></title>
            <link>https://medium.com/@codeaigo/ai-repository-insight-finder-a-streamlit-application-for-discovering-ai-projects-7cb74573cd35?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cb74573cd35</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 17:14:41 GMT</pubDate>
            <atom:updated>2024-10-21T17:14:41.021Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkylssnvXbpevyb0Lk-Cbg.png" /></figure><h4>Introduction</h4><p>In the rapidly evolving field of artificial intelligence (AI) and machine learning (ML), staying updated with the latest repositories on platforms like GitHub is crucial. The <strong>AI Repository Insight Finder</strong> is a Streamlit application designed to help users effortlessly discover and explore AI-related GitHub repositories. This article highlights the key features and functionalities of the application, focusing on the core components of the code.</p><h4>Application Overview</h4><p>The application is structured around a user-friendly interface that allows users to search for AI repositories based on specific queries and programming languages. It utilizes the GitHub API to fetch relevant repositories, providing users with descriptions and links for each repository found.</p><h4>Key Features</h4><ol><li><strong>Streamlit Setup</strong> The application begins by importing the necessary libraries and setting the page configuration with a title and icon:</li></ol><pre>import streamlit as st<br>import requests<br><br>st.set_page_config(page_title=&quot;AI Repository Insight Finder&quot;, page_icon=&quot;🤖&quot;)</pre><p><strong>2. Fetching Repositories</strong> The core functionality of the application is encapsulated in the get_repositories function. This function constructs a search query for the GitHub API, allowing users to filter repositories by name and programming language. The code snippet shows how the function builds the URL and handles the API request:</p><pre>def get_repositories(search_query, language=None):<br>    url = f&quot;https://api.github.com/search/repositories?q={search_query}+topic:machine-learning+topic:artificial-intelligence&quot;<br>    if language:<br>        url += f&quot;+language:{language}&quot;<br>    response = requests.get(url)</pre><p>After fetching the data, the function checks for successful responses, extracts the relevant repository details, and fetches descriptions using individual repository URLs.</p><p><strong>3. User Input Interface</strong> The Streamlit interface allows users to input their search queries and select programming languages. The following code captures user input and integrates it into the search functionality:</p><pre>search_query = st.text_input(&quot;Search AI repositories:&quot;)<br>language = st.selectbox(&quot;Select programming language (optional):&quot;, [&quot;&quot;, &quot;Python&quot;, &quot;JavaScript&quot;, &quot;Java&quot;, &quot;C++&quot;, &quot;Go&quot;])</pre><p><strong>4. Displaying Results</strong> Upon clicking the search button, the application displays the number of repositories found and provides links to each repository along with its description. The output section of the code is structured to handle and display this information:</p><pre>if st.button(&quot;Search&quot;):<br>    if search_query:<br>        repositories = get_repositories(search_query, language)<br>        if repositories:<br>            for repo in repositories:<br>                st.write(f&quot;- [{repo[&#39;name&#39;]}]({repo[&#39;html_url&#39;]}) - {repo[&#39;description&#39;]}&quot;)</pre><p><strong>5. Error Handling</strong> The application includes error handling for API requests, ensuring a smooth user experience by informing users when requests fail or when no results are found.</p><h4>Conclusion</h4><p>The <strong>AI Repository Insight Finder</strong> leverages the power of Streamlit and the GitHub API to provide an efficient tool for discovering AI repositories. With its intuitive interface, users can quickly search and access valuable resources, making it a valuable asset for anyone interested in the AI field. Whether you’re a developer looking for inspiration or a researcher seeking relevant projects, this application is designed to streamline your search for AI repositories.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p><strong>Happy coding and stay tuned for more exciting projects!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cb74573cd35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get the Latest News at Your Fingertips: Building a Google News Fetcher with Python]]></title>
            <link>https://medium.com/@codeaigo/get-the-latest-news-at-your-fingertips-building-a-google-news-fetcher-with-python-9e69d5844a0c?source=rss-7d96c3963537------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e69d5844a0c</guid>
            <category><![CDATA[serpapi]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[google-news]]></category>
            <category><![CDATA[data-extraction]]></category>
            <dc:creator><![CDATA[CodeAIGo]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 13:24:35 GMT</pubDate>
            <atom:updated>2024-10-20T13:24:35.936Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wanted to fetch the latest news about a topic in real-time using Python? In this article, we’ll walk through how to build a simple but powerful Google News Fetcher app using <strong>Streamlit</strong> for the UI and <strong>SerpAPI</strong> for fetching news data. This app allows users to search for news articles on any topic and displays the results with sources and links to the original articles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-q_lB-M0pqVLfz4Pr_A5A.png" /></figure><h3>Why This App?</h3><p>We’re living in a world of constant information flow, and staying up-to-date with news on a specific topic can be challenging. With this app, you can quickly search for relevant news articles and get results instantly without having to navigate through different news websites.</p><h3>Tools We’ll Use</h3><ul><li><strong>Streamlit</strong>: A Python library for creating user-friendly web applications with minimal effort.</li><li><strong>SerpAPI</strong>: A search engine scraping API that makes it easy to retrieve Google News data.</li><li><strong>dotenv</strong>: A package for loading environment variables (API keys) from a .env file.</li></ul><h3>Getting Started</h3><p>To begin, you’ll need an API key from SerpAPI. This key will allow us to connect to Google News and retrieve search results based on a user’s query. We’ll also need Streamlit to create the interface for users to input their queries.</p><h4>Step 1: Setting Up the Environment</h4><p>First, let’s set up our environment. Make sure you have installed the necessary packages:</p><pre>pip install streamlit serpapi python-dotenv</pre><p>Once the installation is done, you need to create a .env file to store your SerpAPI key securely. To get this key, you’ll need to sign up for a free account at <a href="https://serpapi.com/">SerpAPI</a>. After signing up, generate an API key and add it to the .env file:</p><pre>API_KEY=your_serpapi_key</pre><p>This will ensure that your API key remains private and won’t be exposed in your code.</p><h3>Step 2: Building the Core Functionality</h3><p>The main functionality of this app revolves around two tasks:</p><ol><li><strong>Fetching news using the SerpAPI Google News engine</strong></li><li><strong>Displaying the results in an intuitive interface using Streamlit</strong></li></ol><p>Here’s a simplified overview of how we’ll fetch news:</p><ul><li>We’ll use the <strong>serpapi</strong> Python package to interact with the Google News search engine.</li><li>The function fetch_news_serpapi() sends a search query and retrieves the results as a structured JSON.</li><li>The results contain the article title, source, and link, which we’ll display to the user in the app.</li></ul><h3>Fetching News from SerpAPI</h3><p>To start, let’s write a function that sends a query to SerpAPI’s <strong>Google News</strong> engine and processes the results. This function takes a user’s search term and returns the most recent articles that match the query.</p><p>Here’s the core function that handles this:</p><pre>import os<br>from dotenv import load_dotenv<br>from serpapi.google_search import GoogleSearch<br><br># Load the SerpAPI key from environment variables<br>load_dotenv()<br>API_KEY = os.getenv(&quot;API_KEY&quot;)<br><br>def fetch_news_serpapi(query):<br>    # Set up search parameters for SerpAPI<br>    params = {<br>        &quot;engine&quot;: &quot;google_news&quot;,  # Specify that we want Google News results<br>        &quot;q&quot;: query,               # The user&#39;s search query<br>        &quot;gl&quot;: &quot;us&quot;,               # Country of search results (in this case, the United States)<br>        &quot;hl&quot;: &quot;en&quot;,               # Language of the results (in this case, English)<br>        &quot;api_key&quot;: API_KEY        # SerpAPI key for authentication<br>    }<br>    <br>    # Make the search request<br>    search = GoogleSearch(params)<br>    results = search.get_dict()  # Retrieve the search results as a dictionary<br>    news_results = results.get(&quot;news_results&quot;, [])  # Extract the news articles<br>    <br>    # Create a dictionary to hold titles, sources, and links<br>    news_dict = {}<br>    <br>    # Process each article from the results<br>    for article in news_results:<br>        title = article.get(&#39;title&#39;, &#39;No Title Available&#39;)<br>        link = article.get(&#39;link&#39;)<br>        source = article.get(&#39;source&#39;, {}).get(&#39;name&#39;, &#39;Unknown Source&#39;)<br>        <br>        # Store the article&#39;s title, source, and link in the dictionary<br>        if link:<br>            if title not in news_dict:<br>                news_dict[title] = {&#39;sources&#39;: [], &#39;links&#39;: []}<br>            news_dict[title][&#39;sources&#39;].append(source)<br>            news_dict[title][&#39;links&#39;].append(link)<br>        <br>        # Handle additional stories related to the main article<br>        if &#39;stories&#39; in article:<br>            for story in article[&#39;stories&#39;]:<br>                story_link = story.get(&#39;link&#39;)<br>                story_source = story.get(&#39;source&#39;, {}).get(&#39;name&#39;, &#39;Unknown Source&#39;)<br>                <br>                if story_link:<br>                    # Append story details to the existing article entry<br>                    if title not in news_dict:<br>                        news_dict[title] = {&#39;sources&#39;: [], &#39;links&#39;: []}<br>                    news_dict[title][&#39;sources&#39;].append(story_source)<br>                    news_dict[title][&#39;links&#39;].append(story_link)<br>    <br>    return news_dict  # Return the dictionary containing the fetched articles</pre><h3>Explanation of the Code:</h3><ol><li><strong>Search Parameters</strong>: We define the parameters required for <strong>SerpAPI</strong>, specifying that we want news results (&quot;engine&quot;: &quot;google_news&quot;) and pass in the user’s query.</li><li><strong>Result Processing</strong>: The results are fetched and structured in a dictionary format, which contains the title, source, and link to each news article. This allows for easy display later.</li><li><strong>Handling Multiple Stories</strong>: Sometimes, articles come with related stories. The code accounts for these additional stories by including their respective links and sources.</li></ol><h3>Step 3: Building the User Interface with Streamlit</h3><p>Now that we can fetch news, let’s display it in a simple, user-friendly interface using <strong>Streamlit</strong>. Here, users can input their search query, and the app will fetch and display the news results.</p><pre>import streamlit as st<br><br>st.title(&quot;Google News Fetcher with SerpAPI&quot;)<br><br># Input for the search query<br>query_input = st.text_input(&quot;Enter News Query&quot;, &quot;Technology&quot;)<br><br>if st.button(&quot;Fetch News&quot;):<br>    if query_input:<br>        news_articles = fetch_news_serpapi(query_input)<br>        article_count = len(news_articles)  # Count unique articles<br>        <br>        if article_count &gt; 0:<br>            st.subheader(f&quot;Found {article_count} unique articles:&quot;)<br>            for idx, (title, details) in enumerate(news_articles.items()):<br>                st.markdown(f&quot;### {idx + 1}: {title}&quot;)<br>                <br>                # Display sources and links for each article<br>                for source, link in zip(details[&#39;sources&#39;], details[&#39;links&#39;]):<br>                    st.markdown(f&quot;- Source: [**{source}**]({link})&quot;, unsafe_allow_html=True)<br>                st.write(&quot;---&quot;)<br>        else:<br>            st.error(&quot;No articles found.&quot;)<br>    else:<br>        st.error(&quot;Please enter a search query.&quot;)</pre><p>Here’s what this part of the app does:</p><ul><li>The st.text_input() allows users to input a search query.</li><li>When the <strong>“Fetch News”</strong> button is clicked, the app fetches the news articles and displays them in a clean format.</li><li>Each article is displayed with its source and a clickable link.</li></ul><h3>Step 4: Running the App</h3><p>After putting the pieces together, you can run your app locally using:</p><pre>streamlit run app.py</pre><p>This will launch the app in your web browser. Simply type a search term into the input box, hit the “Fetch News” button, and you’ll instantly see the latest news related to your search!</p><h3>Conclusion</h3><p>You’ve just built a <strong>Google News Fetcher</strong> app that fetches real-time news articles based on user input! This app is a great starting point for exploring more advanced features, such as filtering by date or integrating images.</p><p>Feel free to enhance the app by adding features like saved searches or filtering results by country. With the power of <strong>Streamlit</strong> and <strong>SerpAPI</strong>, the possibilities are endless.</p><p>For further details, visit <a href="https://www.codeaigo.se/"><strong>CodeAiGo</strong></a></p><p>Happy coding, and stay tuned for more exciting projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e69d5844a0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>