Dropdead072 commited on
Commit
aacdab1
·
verified ·
1 Parent(s): 5c50b34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -58
app.py CHANGED
@@ -1,69 +1,68 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
3
 
 
 
 
4
 
5
- def respond(
6
- message,
7
- history: list[dict[str, str]],
8
- system_message,
9
- max_tokens,
10
- temperature,
11
- top_p,
12
- hf_token: gr.OAuthToken,
13
- ):
14
- """
15
- 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
16
- """
17
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
 
 
 
 
 
 
 
 
 
18
 
19
- messages = [{"role": "system", "content": system_message}]
20
 
21
- messages.extend(history)
 
 
22
 
23
- messages.append({"role": "user", "content": message})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- response = ""
 
 
26
 
27
- for message in client.chat_completion(
28
- messages,
29
- max_tokens=max_tokens,
30
- stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
- ):
34
- choices = message.choices
35
- token = ""
36
- if len(choices) and choices[0].delta.content:
37
- token = choices[0].delta.content
38
-
39
- response += token
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
- chatbot = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
61
-
62
- with gr.Blocks() as demo:
63
- with gr.Sidebar():
64
- gr.LoginButton()
65
- chatbot.render()
66
 
 
 
 
 
 
67
 
68
  if __name__ == "__main__":
69
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
+ from pipeline import run_course_builder # импортируем твою функцию
4
 
5
+ # Если у тебя API ключи в .env
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
 
9
+ def generate_course(query: str, toc: str, archive_file):
10
+ if archive_file is None:
11
+ return "Пожалуйста, загрузите архив с материалами (.zip)", ""
12
+
13
+ try:
14
+ # Сохраняем загруженный файл временно
15
+ temp_path = "temp_materials.zip"
16
+ with open(temp_path, "wb") as f:
17
+ f.write(archive_file.read())
18
+
19
+ result = run_course_builder(query, toc, temp_path)
20
+
21
+ # Если result — строка (markdown), возвращаем её
22
+ if isinstance(result, str):
23
+ markdown = result
24
+ else:
25
+ markdown = result.get("markdown", result.get("result", str(result)))
26
+
27
+ return "✅ Курс успешно сгенерирован!", markdown
28
+
29
+ except Exception as e:
30
+ return f"❌ Ошибка: {str(e)}", ""
31
 
32
+ # ====================== Gradio Interface ======================
33
 
34
+ with gr.Blocks(title="Генератор учебных курсов", theme=gr.themes.Soft()) as demo:
35
+ gr.Markdown("# 📚 Генератор Интенсивных Учебных Курсов")
36
+ gr.Markdown("Загрузи оглавление + архив с материалами → получи красивый понедельный план")
37
 
38
+ with gr.Row():
39
+ with gr.Column(scale=2):
40
+ query_input = gr.Textbox(
41
+ label="Запрос / Описание курса",
42
+ placeholder="Напиши мне интенсивный курс на 9 недель по алгебре и введению в алгебраическую геометрию...",
43
+ lines=3
44
+ )
45
+ toc_input = gr.Textbox(
46
+ label="Оглавление (TOC)",
47
+ placeholder="Вставь оглавление курса...",
48
+ lines=10
49
+ )
50
+ file_input = gr.File(
51
+ label="Архив с материалами (.zip)",
52
+ file_types=[".zip"]
53
+ )
54
 
55
+ with gr.Column(scale=3):
56
+ output_status = gr.Textbox(label="Статус", interactive=False)
57
+ output_markdown = gr.Markdown(label="Сгенерированный курс", height=800)
58
 
59
+ btn = gr.Button("🚀 Сгенерировать курс", variant="primary", size="large")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ btn.click(
62
+ fn=generate_course,
63
+ inputs=[query_input, toc_input, file_input],
64
+ outputs=[output_status, output_markdown]
65
+ )
66
 
67
  if __name__ == "__main__":
68
+ demo.launch()