Spaces:
Runtime error
Runtime error
import gradio as gr | |
import requests | |
from bs4 import BeautifulSoup | |
import os | |
# =================================================== | |
import psutil | |
def get_cpu_spec(): | |
cpu_info = {} | |
# cpu_info['Brand'] = psutil.cpu_brand() | |
cpu_info['Architecture'] = psutil.cpu_freq().current / 1000 # Convert to GHz | |
cpu_info['Physical cores'] = psutil.cpu_count(logical=False) | |
cpu_info['Total cores'] = psutil.cpu_count(logical=True) | |
return cpu_info | |
def get_ram_info(): | |
ram = psutil.virtual_memory() | |
ram_info = { | |
'Total': round(ram.total / (1024 ** 3), 2), # Convert to GB | |
'Available': round(ram.available / (1024 ** 3), 2), | |
'Used': round(ram.used / (1024 ** 3), 2), | |
'Percentage': ram.percent | |
} | |
return ram_info | |
def print_system_info(): | |
cpu_spec = get_cpu_spec() | |
ram_info = get_ram_info() | |
print("CPU Specifications:") | |
for key, value in cpu_spec.items(): | |
print(f"{key}: {value}") | |
print("\nRAM Information:") | |
for key, value in ram_info.items(): | |
print(f"{key}: {value} GB") | |
print_system_info() | |
print("secret test",os.environ["URL"]) | |
# =================================================== | |
def fetch_text(url): | |
response = requests.get(url) | |
print("response",response) | |
if response.status_code == 200: | |
content = response.text | |
print("content",content) | |
soup = BeautifulSoup(content, 'html.parser') | |
print("soup",soup) | |
find_all_text = soup.find_all('p') | |
print("find_all_text",find_all_text) | |
text_arr = [] | |
for p in find_all_text: | |
p_get_text = p.get_text() | |
print("p_get_text",p_get_text) | |
text_arr.append(p_get_text) | |
print("text_arr",text_arr) | |
clean_text = ' '.join([p.get_text() for p in soup.find_all('p')]) | |
print("clean_text",clean_text) | |
return clean_text | |
else : | |
return "" | |
#=============================================================== | |
with gr.Blocks() as app: | |
gr.Markdown("# QA Model testing") | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown("## Crawl Source") | |
with gr.Row(): | |
link = gr.Textbox(label="link") | |
crawl_btn = gr.Button("crawl source", interactive=True) | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown("## Input Text") | |
with gr.Row(): | |
title = gr.Textbox(label="title") | |
summary = gr.Textbox(label="summary") | |
maintext = gr.Textbox(label="maintext") | |
crawl_btn.click(fn=fetch_text, inputs=link, outputs=maintext) | |
app.launch() |