Update app.py
Browse files275 unmodified lines27627727827927928028128228328328428528628728828929028529129229329420 unmodified lines31531631731231831932032115 unmodified lines337338339334340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391190 unmodified lines582583584585586587588589590591592593594595596597598599600601602603604605606607275 unmodified lines return summary, cleaned_summary
def process_google_news_rss(query, temperature, top_p, repetition_penalty):def process_news(query, temperature, top_p, repetition_penalty, news_source): model = get_model(temperature, top_p, repetition_penalty) embed = get_embeddings() if news_source == "Google News RSS": articles = fetch_google_news_rss(query) articles = fetch_google_news_rss(query) elif news_source == "Golomt Bank": articles = fetch_golomt_bank_news() else: return "Invalid news source selected." if not articles: return "No news articles found for the given query." return f"No news articles found for the given {news_source}." processed_articles = [] 20 unmodified lines print(f"Error processing article: {str(e)}") if not processed_articles: return "Failed to process any news articles. Please try a different query or check the summarization process." return f"Failed to process any news articles from {news_source}. Please try again or check the summarization process." # Add processed articles to the database docs = [Document(page_content=article["cleaned_summary"], metadata={15 unmodified lines global news_database news_database.extend(processed_articles) return f"Processed and added {len(processed_articles)} news articles to the database." return f"Processed and added {len(processed_articles)} news articles from {news_source} to the database." except Exception as e: return f"Error adding articles to the database: {str(e)}"
def fetch_golomt_bank_news(num_results=10): base_url = "https://golomtbank.com/en/investor-relations" try: response = requests.get(base_url) response.raise_for_status() soup = BeautifulSoup(response.content, 'html.parser') articles = soup.find_all('article', class_='gt-post') news_items = [] for article in articles[:num_results]: title_div = article.find('h5', class_='gt-carousel-title') title = title_div.get_text(strip=True) if title_div else "No Title" date_div = article.find('div', class_='entry-date gt-meta') date = date_div.get_text(strip=True) if date_div else "No Date" link_tag = article.find('a') link = link_tag['href'] if link_tag else "No Link" if not link.startswith('http'): link = "https://golomtbank.com" + link try: article_response = requests.get(link) article_response.raise_for_status() article_soup = BeautifulSoup(article_response.content, 'html.parser') article_content_div = article_soup.find('div', class_='entry-post') content = article_content_div.get_text(strip=True) if article_content_div else "No content found" except Exception as e: content = f"Error fetching article content: {str(e)}" news_item = { "published_date": date, "title": title, "url": link, "content": content } news_items.append(news_item) return news_items except Exception as e: print(f"Error fetching Golomt Bank news: {str(e)}") return [] def export_news_to_excel(): global news_database df = pd.DataFrame(news_database)190 unmodified lines fetch_news_button = gr.Button("Fetch News") news_fetch_output = gr.Textbox(label="News Fetch Status")
with gr.Row(): news_source_dropdown = gr.Dropdown( choices=["Google News RSS", "Golomt Bank"], label="Select News Source", value="Google News RSS" ) news_query_input = gr.Textbox(label="Enter news query (for Google News RSS)") fetch_news_button = gr.Button("Fetch News") news_fetch_output = gr.Textbox(label="News Fetch Status") def fetch_news(query, temperature, top_p, repetition_penalty, news_source): return process_news(query, temperature, top_p, repetition_penalty, news_source)
fetch_news_button.click( fetch_news, inputs=[news_query_input, temperature_slider, top_p_slider, repetition_penalty_slider, news_source_dropdown], outputs=news_fetch_output ) def chat(question, history, temperature, top_p, repetition_penalty, web_search, google_news_rss): answer = ask_question(question, temperature, top_p, repetition_penalty, web_search, google_news_rss)app.py+76-5