Spaces:
Sleeping
Sleeping
Change IBM Granite Model
Browse files
app.py
CHANGED
@@ -1,39 +1,39 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import requests
|
3 |
-
import os # Importiere das os-Modul, um Secrets zu verwenden
|
4 |
-
|
5 |
-
# Hugging Face API Key wird aus den Hugging Face Secrets geladen
|
6 |
-
HF_API_KEY = os.getenv("IBMGraniteTextSummary")
|
7 |
-
|
8 |
-
# IBM Granite 3B Modell
|
9 |
-
MODEL_NAME = "ibm/granite-
|
10 |
-
|
11 |
-
# Funktion zur Textzusammenfassung
|
12 |
-
def summarize_text(text):
|
13 |
-
if not HF_API_KEY:
|
14 |
-
return "Fehler: Kein API-Key gefunden. Bitte überprüfe die Hugging Face Secrets."
|
15 |
-
|
16 |
-
url = f"https://api-inference.huggingface.co/models/{MODEL_NAME}"
|
17 |
-
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
18 |
-
payload = {"inputs": text}
|
19 |
-
|
20 |
-
response = requests.post(url, headers=headers, json=payload)
|
21 |
-
|
22 |
-
if response.status_code == 200:
|
23 |
-
result = response.json()
|
24 |
-
return result[0]["generated_text"] if result else "Keine Antwort erhalten."
|
25 |
-
else:
|
26 |
-
return f"Fehler: {response.status_code} - {response.text}"
|
27 |
-
|
28 |
-
# Gradio UI
|
29 |
-
iface = gr.Interface(
|
30 |
-
fn=summarize_text,
|
31 |
-
inputs=gr.Textbox(label="Gib deinen Text ein", lines=5),
|
32 |
-
outputs=gr.Textbox(label="Zusammenfassung"),
|
33 |
-
title="IBM Granite Text Summarizer",
|
34 |
-
description="Dieses Tool nutzt IBM Granite-3B, um Texte zusammenzufassen. Gib einen langen Text ein, und Granite erstellt eine kurze Zusammenfassung!"
|
35 |
-
)
|
36 |
-
|
37 |
-
# App starten
|
38 |
-
if __name__ == "__main__":
|
39 |
-
iface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os # Importiere das os-Modul, um Secrets zu verwenden
|
4 |
+
|
5 |
+
# Hugging Face API Key wird aus den Hugging Face Secrets geladen
|
6 |
+
HF_API_KEY = os.getenv("IBMGraniteTextSummary")
|
7 |
+
|
8 |
+
# IBM Granite 3B Modell
|
9 |
+
MODEL_NAME = "ibm-granite/granite-3.0-1b-a400m-instruct"
|
10 |
+
|
11 |
+
# Funktion zur Textzusammenfassung
|
12 |
+
def summarize_text(text):
|
13 |
+
if not HF_API_KEY:
|
14 |
+
return "Fehler: Kein API-Key gefunden. Bitte überprüfe die Hugging Face Secrets."
|
15 |
+
|
16 |
+
url = f"https://api-inference.huggingface.co/models/{MODEL_NAME}"
|
17 |
+
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
18 |
+
payload = {"inputs": text}
|
19 |
+
|
20 |
+
response = requests.post(url, headers=headers, json=payload)
|
21 |
+
|
22 |
+
if response.status_code == 200:
|
23 |
+
result = response.json()
|
24 |
+
return result[0]["generated_text"] if result else "Keine Antwort erhalten."
|
25 |
+
else:
|
26 |
+
return f"Fehler: {response.status_code} - {response.text}"
|
27 |
+
|
28 |
+
# Gradio UI
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=summarize_text,
|
31 |
+
inputs=gr.Textbox(label="Gib deinen Text ein", lines=5),
|
32 |
+
outputs=gr.Textbox(label="Zusammenfassung"),
|
33 |
+
title="IBM Granite Text Summarizer",
|
34 |
+
description="Dieses Tool nutzt IBM Granite-3B, um Texte zusammenzufassen. Gib einen langen Text ein, und Granite erstellt eine kurze Zusammenfassung!"
|
35 |
+
)
|
36 |
+
|
37 |
+
# App starten
|
38 |
+
if __name__ == "__main__":
|
39 |
+
iface.launch()
|