Mauro24 commited on
Commit
5bb1c61
·
verified ·
1 Parent(s): 59643d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,13 +1,13 @@
1
 
 
2
  import gradio as gr
3
  from langchain_community.vectorstores import FAISS
4
  from langchain_community.embeddings import HuggingFaceEmbeddings
5
  import zipfile
6
  import os
7
- import openai
8
  import torch
9
 
10
- # Carica la chiave API di OpenAI dalle variabili d'ambiente
11
  openai.api_key = os.getenv("OPENAI_API_KEY")
12
 
13
  # Percorsi ZIP per manuali e problemi
@@ -43,17 +43,22 @@ def search_and_summarize(query):
43
 
44
  combined_text = f"Manual Results:\n{manual_output}\n\nProblems Results:\n{problems_output}"
45
 
46
- # Generazione del riassunto con OpenAI
47
  input_text = f"Riassumi le seguenti informazioni:\n{combined_text}\n\nRiassunto:"
48
- response = openai.Completion.create(
49
- engine="text-davinci-003", # Puoi scegliere un altro modello se preferisci
50
- prompt=input_text,
51
- max_tokens=300,
 
 
 
 
 
52
  temperature=0.7
53
  )
54
-
55
- summary = response.choices[0].text.strip()
56
 
 
 
57
  return manual_output, problems_output, summary
58
 
59
  # Interfaccia Gradio
@@ -63,17 +68,18 @@ iface = gr.Interface(
63
  outputs=[
64
  gr.Textbox(label="Manual Results"),
65
  gr.Textbox(label="Issues Results"),
66
- gr.Textbox(label="Summary by OpenAI")
67
  ],
68
  examples=[
69
  ["How to change the knife?"],
70
  ["What are the safety precautions for using the machine?"],
71
  ["How can I get help with the machine?"]
72
  ],
73
- title="Manual Querying System with OpenAI Summarization",
74
- description="Enter a question to get information from the manual and the common issues, summarized by OpenAI."
75
  )
76
 
77
  # Avvia l'app Gradio
78
  iface.launch()
79
 
 
 
1
 
2
+ import openai
3
  import gradio as gr
4
  from langchain_community.vectorstores import FAISS
5
  from langchain_community.embeddings import HuggingFaceEmbeddings
6
  import zipfile
7
  import os
 
8
  import torch
9
 
10
+ # Imposta la tua chiave API di OpenAI come variabile d'ambiente
11
  openai.api_key = os.getenv("OPENAI_API_KEY")
12
 
13
  # Percorsi ZIP per manuali e problemi
 
43
 
44
  combined_text = f"Manual Results:\n{manual_output}\n\nProblems Results:\n{problems_output}"
45
 
46
+ # Generazione del riassunto con OpenAI GPT-3 (nuova API)
47
  input_text = f"Riassumi le seguenti informazioni:\n{combined_text}\n\nRiassunto:"
48
+
49
+ # Chiamata all'API OpenAI per generare il riassunto usando la nuova interfaccia
50
+ response = openai.ChatCompletion.create(
51
+ model="gpt-3.5-turbo", # Puoi scegliere anche "gpt-4" o altri modelli
52
+ messages=[
53
+ {"role": "system", "content": "Sei un assistente che aiuta con la sintesi di informazioni."},
54
+ {"role": "user", "content": input_text}
55
+ ],
56
+ max_tokens=150,
57
  temperature=0.7
58
  )
 
 
59
 
60
+ summary = response['choices'][0]['message']['content'].strip()
61
+
62
  return manual_output, problems_output, summary
63
 
64
  # Interfaccia Gradio
 
68
  outputs=[
69
  gr.Textbox(label="Manual Results"),
70
  gr.Textbox(label="Issues Results"),
71
+ gr.Textbox(label="Summary by GPT-3")
72
  ],
73
  examples=[
74
  ["How to change the knife?"],
75
  ["What are the safety precautions for using the machine?"],
76
  ["How can I get help with the machine?"]
77
  ],
78
+ title="Manual Querying System with GPT-3 Summarization",
79
+ description="Enter a question to get information from the manual and the common issues, summarized by GPT-3."
80
  )
81
 
82
  # Avvia l'app Gradio
83
  iface.launch()
84
 
85
+