Spaces:
Running
Running
Download index.html from danylokk/summarizing-text: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/danylokk/summarizing-text/resolve/main/index.html
- Command line
-
hf download hf://spaces/danylokk/summarizing-text/index.html
-
curl -L -o index.html https://huggingface.co/spaces/danylokk/summarizing-text/resolve/main/index.html
2.37 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Groq Summarizer - Gradio Lite</title> | |
| <!-- Load Gradio-Lite CSS and JS --> | |
| <script type="module" src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" /> | |
| </head> | |
| <body> | |
| <gradio-lite> | |
| <!-- No external requirements needed; uses standard urllib --> | |
| <gradio-file name="app.py"> | |
| import gradio as gr | |
| import urllib.request | |
| import json | |
| def summarize_text(api_key, text): | |
| if not api_key: | |
| return "Please provide an API key." | |
| if not text: | |
| return "Please provide text to summarize." | |
| url = "https://api.groq.com/openai/v1/chat/completions" | |
| headers = { | |
| "Authorization": f"Bearer {api_key.strip()}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": "llama-3.1-8b-instant", | |
| "messages": [ | |
| {"role": "system", "content": "You are a helpful assistant that summarizes text clearly and concisely."}, | |
| {"role": "user", "content": f"Summarize the following text:\n\n{text}"} | |
| ] | |
| } | |
| try: | |
| req = urllib.request.Request( | |
| url, | |
| data=json.dumps(payload).encode("utf-8"), | |
| headers=headers, | |
| method="POST" | |
| ) | |
| with urllib.request.urlopen(req) as response: | |
| res_data = json.loads(response.read().decode("utf-8")) | |
| return res_data["choices"][0]["message"]["content"] | |
| except urllib.error.HTTPError as e: | |
| error_body = e.read().decode("utf-8") | |
| return f"HTTP Error {e.code}: {error_body}" | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| api_key = gr.Textbox(label="Groq API Key", type="password", placeholder="gsk_...") | |
| text = gr.Textbox(label="Text to summarize", lines=6, placeholder="Paste text here...") | |
| output_text = gr.Textbox(label="Summary") | |
| demo = gr.Interface( | |
| title="Summarize a text!", | |
| description="Simple app running completely in your browser via Gradio-Lite.", | |
| fn=summarize_text, | |
| inputs=[api_key, text], | |
| outputs=[output_text] | |
| ) | |
| demo.launch() | |
| </gradio-file> | |
| </gradio-lite> | |
| </body> | |
| </html> |