File size: 2,364 Bytes
a6e5fa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a1319e
a6e5fa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a1319e
 
a6e5fa3
 
 
 
 
 
1a1319e
 
a6e5fa3
1a1319e
a6e5fa3
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# %%
from transformers import (
    pipeline,
    AutoModelForCausalLM,
    GenerationConfig
)
import requests 
import gradio as gr
from bs4 import BeautifulSoup
import torch



# %%
def search(subject):
    #search the news for subject
    base_url = "https://www.bing.com/search"
    query = requests.utils.quote(subject)
    count = 3
    url = f"{base_url}?q={query}&count={count}"
    response = requests.get(url)
    if response.status_code == 200:
        print("The request was successful!")

    soup = BeautifulSoup(response.content, "html.parser")
    results = soup.find_all("li")
    titles = []
    texts = []
    for result in results:
        title = result.find("h2")
        text = result.find("p")
        if title and text:
            titles.append(title.text)
            texts.append(text.text)
    texts = "".join(texts)   
    #print(texts)
     
    return texts

    


    

# %%
def answer(inp):
    pipe = pipeline("conversational","HuggingFaceH4/zephyr-7b-beta")
    chat = [
        {"role": "system", "content": "As our News Analysis Assistant, your primary responsibility is to thoroughly read and interpret all the latest news articles that are given to you. Once you have comprehensively analyzed these pieces, your task is to condense their essential elements into succinct and precise summaries in English language and Persian. These summaries should accurately convey the most pertinent details while preserving the original meaning and intent of the source material. By doing so, you'll provide our users with timely and trustworthy reports on the topics they care about, no matter where those stories originate. Thank you for taking on this critical role, and we look forward to seeing how your expertise contributes to improving our platform's overall quality and effectiveness."},
        {"role": "user", "content": search(inp)},
        {"role": "assistant", "content": "here is a summary about" + inp}
    ]
    return pipe(chat)

# %%
#output = answer(input("enter question"))
#print(output)

# %%
with gr.Blocks() as demo:
    gr.Markdown("# News Analysis Assistant")
    with gr.Row():
            subject = gr.Textbox(label="Subject")
            results = gr.Textbox()
    with gr.Row():
            submit = gr.Button("Submit")
    submit.click(answer, inputs=subject, outputs=results)
demo.launch(share=True)