Update space
Browse files
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
@@ -40,25 +43,70 @@ def respond(
|
|
| 40 |
yield response
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
"""
|
| 44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
"""
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
)
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import requests
|
| 4 |
+
from bs4 import BeautifulSoup
|
| 5 |
+
import pandas as pd
|
| 6 |
|
| 7 |
"""
|
| 8 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
|
|
| 43 |
yield response
|
| 44 |
|
| 45 |
|
| 46 |
+
def extract_table(url):
|
| 47 |
+
try:
|
| 48 |
+
response = requests.get(url)
|
| 49 |
+
response.raise_for_status()
|
| 50 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 51 |
+
table = soup.find('table')
|
| 52 |
+
if not table:
|
| 53 |
+
return "<p>No table found on page</p>"
|
| 54 |
+
|
| 55 |
+
data = []
|
| 56 |
+
rows = table.find_all('tr')
|
| 57 |
+
for row in rows[1:]:
|
| 58 |
+
cells = row.find_all('td')
|
| 59 |
+
if len(cells) >= 2:
|
| 60 |
+
data.append({
|
| 61 |
+
'Column 1': cells[0].text.strip(),
|
| 62 |
+
'Column 2': cells[1].text.strip()
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
df = pd.DataFrame(data)
|
| 66 |
+
return df.to_html(index=False)
|
| 67 |
+
except Exception as e:
|
| 68 |
+
return f"<p>Error: {str(e)}</p>"
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def display_table(url):
|
| 72 |
+
return extract_table(url)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
"""
|
| 76 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 77 |
"""
|
| 78 |
+
with gr.Blocks() as demo:
|
| 79 |
+
with gr.Row():
|
| 80 |
+
with gr.Column(scale=1):
|
| 81 |
+
url_input = gr.Textbox(
|
| 82 |
+
value="https://example.com/table",
|
| 83 |
+
label="Table URL"
|
| 84 |
+
)
|
| 85 |
+
table_output = gr.HTML(label="Extracted Table")
|
| 86 |
+
extract_btn = gr.Button("Extract Table")
|
| 87 |
+
|
| 88 |
+
extract_btn.click(
|
| 89 |
+
fn=display_table,
|
| 90 |
+
inputs=[url_input],
|
| 91 |
+
outputs=[table_output]
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
with gr.Column(scale=2):
|
| 95 |
+
chatbot = gr.ChatInterface(
|
| 96 |
+
respond,
|
| 97 |
+
additional_inputs=[
|
| 98 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 99 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 100 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 101 |
+
gr.Slider(
|
| 102 |
+
minimum=0.1,
|
| 103 |
+
maximum=1.0,
|
| 104 |
+
value=0.95,
|
| 105 |
+
step=0.05,
|
| 106 |
+
label="Top-p (nucleus sampling)",
|
| 107 |
+
),
|
| 108 |
+
],
|
| 109 |
+
)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
+
demo.launch()
|